QAQ的公式求解(一)

QAQ的公式求解(一)

时间限制: 1 Sec   内存限制: 128 MB
提交: 113   解决: 51
[ 提交][ 状态][ 讨论版]

题目描述

QAQ给定一个小公式,即: f[i]=f[i1]x f[i]=f[i−1]∗x i>=2 i>=2)。他想知道 f[n] f[n]的结果。

输入

第一行输入一个整数 T T,代表有 T T组测试数据。

每组数据输入三个整数 f[1]xn f[1]、x、n,分别代表上面提到的信息。


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



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值