QAQ的公式求解(一)
时间限制: 1 Sec 内存限制: 128 MB提交: 113 解决: 51
[ 提交][ 状态][ 讨论版]
题目描述
QAQ给定一个小公式,即:
f[i]=f[i−1]∗x
f[i]=f[i−1]∗x(
i>=2
i>=2)。他想知道
f[n]
f[n]的结果。
输入
第一行输入一个整数
T
T,代表有
T
T组测试数据。
每组数据输入三个整数 f[1]、x、n f[1]、x、n,分别代表上面提到的信息。
注: 1<=T<=10000,1<=f[1],x,n<=109 1<=T<=10000,1<=f[1],x,n<=109。
输出
对每组测试数据,输出一个整数代表最后的结果。
由于结果很大,请对 109+7 109+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