QAQ的公式求解(一)
時間限制: 1 Sec 內存限制: 128 MB提交: 113 解決: 51
[提交][狀態][討論版]
題目描述
輸入
每組數據輸入三個整數f[1]、x、nf[1]、x、n,分別代表上面提到的信息。
注:1<=T<=10000,1<=f[1],x,n<=1091<=T<=10000,1<=f[1],x,n<=109。
輸出
對每組測試數據,輸出一個整數代表最後的結果。
由於結果很大,請對109+7109+7取餘。
樣例輸入
3
1 1 1
4 5 6
7 8 9
樣例輸出
1
12500
117440512
根據公式用快速冪即可ac
#include<cstdio>
#include<iostream>
#include<cstring>
#include<cmath>
#include<algorithm>
typedef long long LL;
using namespace std;
const int N = 1*1e9+7;
LL quicklow(int a,int b){
LL ans=1,base=a;
while(b){
if(b&1){
ans=ans*base%N;
}
base=base*base%N;
b=b>>1;
}
return ans;
}
int main(){
int f1,x,n,T;
scanf("%d",&T);
while(T--){
scanf("%d%d%d",&f1,&x,&n);
LL ans=f1*quicklow(x,n-1)%N;
printf("%lld\n",ans);
}
return 0;
}
http://acm.hpu.edu.cn/problem.php?cid=1002&pid=5