QAQ的公式求解(一)

QAQ的公式求解(一)

時間限制: 1 Sec  內存限制: 128 MB
提交: 113  解決: 51
[提交][狀態][討論版]

題目描述

QAQ給定一個小公式,即:f[i]=f[i1]xf[i]=f[i−1]∗xi>=2i>=2)。他想知道f[n]f[n]的結果。

輸入

第一行輸入一個整數TT,代表有TT組測試數據。

每組數據輸入三個整數f[1]xnf[1]、x、n,分別代表上面提到的信息。


注:1<=T<=100001<=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



發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章