题目:
分析:
用快速幂套入公式怒拿
1
A
1A
1A
千万要记得除法取模时要使用费马小定理
代码:
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<set>
#include<queue>
#include<vector>
#include<map>
#include<list>
#include<ctime>
#include<iomanip>
#include<string>
#include<bitset>
#include<deque>
#include<set>
#define LL long long
#define mo (LL)1e9+7
using namespace std;
inline LL read(){
LL d=0,f=1;char s=getchar();
while(s<'0'||s>'9'){if(s=='-')f=-1;s=getchar();}
while(s>='0'&&s<='9'){d=d*10+s-'0';s=getchar();}
return d*f;
}
LL ksm(LL x,LL y)
{
LL s=1;
while(y)
{
if(y%2) (s*=x)%=1000000007;
y/=2;(x*=x)%=1000000007;
}
return s;
}
int main()
{
LL q=read();
while(q--)
{
LL a=read(),b=read(),c=read();
if(b==1) {printf("%lld\n",a*(c%1000000007)%1000000007);continue;}
LL x=ksm(b,c),y=ksm(b-1,1000000005);
printf("%lld\n",(a*(x-1)%1000000007*y)%1000000007);
}
return 0;
}