#line 1 "src/alfred/math/speed-of-light-power.hpp"
#line 1 "src/alfred/math/utils.hpp"
// O(sqrt(x)) to judge if x is a prime.// It will be re-written in Miller-rabin sometime.constexprboolis_prime(longlongx){if(x<2)returnfalse;for(longlongi=2;i*i<=x;i++){if(x%i==0)returnfalse;}returntrue;}template<classT>inlineTgcd(Ta,Tb){returnb==0?a:gcd(b,a%b);}template<classT>inlineTlcm(Ta,Tb){returna/gcd(a,b)*b;}#line 5 "src/alfred/math/speed-of-light-power.hpp"
#include<cmath>
#include<vector>template<intbase,intmod>structSOLPower{// Speed Of Light Power. O(sqrt(n)) ~ O(1)// p1 stores base^0 ~ base^sq// ps stores base^sq ~ base^(sq^2)std::vector<int>p1,ps;staticconstboolP=is_prime(mod);staticconstintsq=std::sqrt(mod);SOLPower(void){p1.push_back(1),ps.push_back(1);for(inti=1;i<=sq;i++){p1.push_back(1ll*p1.back()*base%mod);}ps.push_back(p1.back());for(inti=2*sq;i<=mod;i+=sq){ps.push_back(1ll*ps.back()*ps[1]%mod);}}inlineintpower(longlongindex){if(P&&index>=mod)index%=mod;return1ll*ps[index/sq]*p1[index%sq]%mod;}};