|
|
|
@ -3,16 +3,34 @@ |
|
|
|
|
|
|
|
|
|
std::map<internal::PowModStruct,int>utils::mapping; |
|
|
|
|
|
|
|
|
|
int utils::PowMod(int a,int b, int mod){ |
|
|
|
|
long utils::PowMod(int a,int b, int mod){ |
|
|
|
|
int shift=0; |
|
|
|
|
for(int n=1;n<=b;n*=2){ |
|
|
|
|
long product=0; |
|
|
|
|
for(long n=1;n<=b;n*=2){ |
|
|
|
|
if(utils::mapping.find({a,n,mod})!=utils::mapping.end()){ |
|
|
|
|
std::cout<<internal::PowModStruct{a,n,mod}<<"="<<utils::mapping[{a,n,mod}]<<std::endl; |
|
|
|
|
if(b&n){ |
|
|
|
|
if(product==0){ |
|
|
|
|
product=1; |
|
|
|
|
} |
|
|
|
|
std::cout<<utils::mapping[{a,n,mod}]<<std::endl; |
|
|
|
|
product*=utils::mapping[{a,n,mod}]; |
|
|
|
|
product%=mod; |
|
|
|
|
} |
|
|
|
|
continue; |
|
|
|
|
} |
|
|
|
|
std::cout<<std::fmod(std::pow(double(a),double(n)),double(mod))<<std::endl; |
|
|
|
|
utils::mapping[{a,n,mod}]=std::fmod(std::pow(double(a),double(n)),double(mod)); |
|
|
|
|
if(n==1){ |
|
|
|
|
utils::mapping[{a,n,mod}]=a%mod; |
|
|
|
|
}else{ |
|
|
|
|
utils::mapping[{a,n,mod}]=long(utils::mapping[{a,n/2,mod}])*utils::mapping[{a,n/2,mod}]%mod; |
|
|
|
|
} |
|
|
|
|
if(b&n){ |
|
|
|
|
if(product==0){ |
|
|
|
|
product=1; |
|
|
|
|
} |
|
|
|
|
product*=utils::mapping[{a,n,mod}]; |
|
|
|
|
product%=mod; |
|
|
|
|
} |
|
|
|
|
shift++; |
|
|
|
|
} |
|
|
|
|
return 0; |
|
|
|
|
return product%mod; |
|
|
|
|
} |