Submission #3796

#TimeUsernameProblemLanguageResultExecution timeMemory
3796zzapcoderGreat Pow! (kriii1_G)C++98
0 / 1
0 ms1672 KiB
#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 timeMemoryGrader output
Fetching results...