답안 #19458

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
19458 2016-02-24T12:56:59 Z codingman Α (kriii4_P1) C++14
100 / 100
0 ms 1720 KB
#include <fstream>
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <stack>
#include <string>
#include <regex>
#include <map>
#include <numeric>
using namespace std;
vector<string> s;
//string c;

unsigned long long A, X;
vector<unsigned long long> Avector;
/*
첫 번째 줄에는 정수 A(1?≤?A?≤?10^18)이 주어진다.

두 번째 줄에는 정수 X(1?≤?X?≤?10^18)가 주어진다.
*/
int main()
{ 
	cin >> A >> X;
	unsigned long long mod = 1000000007;
	//Avector.push_back(1);

	unsigned long long temp = 1;
	Avector.push_back(A);
	//long long prevValue = A;
	unsigned long long cnt = 1;
	while(1)
	{
		//if(temp >= X)
		//{
		//	break;
		//} 
		auto t = (Avector.back() % mod)* (Avector.back() % mod) % mod;
		if(cnt > X)
			break;
		else 
			Avector.push_back(t); 
		cnt <<= 1;
	}

	
	unsigned long long tX = X;
	vector<int> binary;
	while(tX)
	{
		//printf("%d", tX % 2);
		binary.push_back(tX % 2);
		//cout << tX % 2 << endl;
		tX /= 2;

	}

	long long result = 1;
	for(int i=0; i<binary.size(); i++)
	{
		if(binary[i])
		{
			result = (result  % mod) * (Avector[i] % mod) % mod; 
		}
	}


	cout << result;


	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 1720 KB Output is correct
2 Correct 0 ms 1720 KB Output is correct
3 Correct 0 ms 1720 KB Output is correct
4 Correct 0 ms 1720 KB Output is correct
5 Correct 0 ms 1720 KB Output is correct
6 Correct 0 ms 1720 KB Output is correct
7 Correct 0 ms 1720 KB Output is correct
8 Correct 0 ms 1720 KB Output is correct
9 Correct 0 ms 1720 KB Output is correct
10 Correct 0 ms 1720 KB Output is correct
11 Correct 0 ms 1720 KB Output is correct
12 Correct 0 ms 1720 KB Output is correct
13 Correct 0 ms 1720 KB Output is correct
14 Correct 0 ms 1720 KB Output is correct
15 Correct 0 ms 1720 KB Output is correct
16 Correct 0 ms 1720 KB Output is correct
17 Correct 0 ms 1720 KB Output is correct
18 Correct 0 ms 1720 KB Output is correct
19 Correct 0 ms 1720 KB Output is correct
20 Correct 0 ms 1720 KB Output is correct