Submission #3796

# Submission time Handle Problem Language Result Execution time Memory
3796 2013-08-31T08:24:28 Z zzapcoder Great Pow! (kriii1_G) C++
0 / 1
0 ms 1672 KB
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>


using namespace std;

int sq(int a, int k){

	if(k == 0) return 1;
	if(k == 1) return a;

	int ans = 1;
	if(k&1) ans = a;

	return ((ans * sq(a, k/2))%(a+1) * sq(a, k/2) ) % (a+1);
}


int powk(int a, int k){
	if(k == 0) return a;
	return sq(a, powk(a,k-1))%(a+1);
}

int main(){
	int a,k;
	cin >> a >> k;
	cout<<powk(a, k)<<endl;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 1672 KB Output is correct
2 Incorrect 0 ms 1672 KB Output isn't correct
3 Halted 0 ms 0 KB -