# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
3796 | zzapcoder | Great Pow! (kriii1_G) | C++98 | 0 ms | 1672 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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 |
---|---|---|---|---|
Fetching results... |