快速幂中,数据类型根据题意来,可能是int, double, long long。中间计算结果防止溢出故再多乘1ll,同理如果是加法(本题中没遇到)就+0ll
class Solution {
public:intmaxNiceDivisors(int primeFactors){if(primeFactors==1)return1;if(primeFactors==2)return2;int mod =1e9+7;int a = primeFactors/3;if(primeFactors%3==0)returnqmi(3,a,mod)%mod;if(primeFactors%3==1)returnqmi(3,a-1,mod)*1ll*4%mod;if(primeFactors%3==2)returnqmi(3,a,mod)*1ll*2%mod;return0;}intqmi(int m,int k,int p){int res =1, t = m;while(k){if(k&1) res = res *1ll* t % p;
t = t *1ll*t % p;
k >>=1;}return res%p;}};