hdu2817 A sequence of numbers

这题就是判断是等差数列还是等比数列,然后计算结果mod200907  

因为数字比较大10的九次方

所以等比用到了快速幂求模

不懂可以看看算法导论,在大数那里有讲


#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int modPow(__int64 x,__int64 y) //计算x的y次方求余        快速幂不懂可以百度
{
    __int64  res=1,a=x;
    while (y>0)
	{
		if(y&1) 
		{
			res=(res*a)%200907;
		}
		a=(a*a)%200907;
		y>>=1;
    }
	return res;
}


int main()
{
	__int64 k,ans,ca,n,a,b,c,bi;
	scanf("%I64d",&n);
	while(n--)
	{
		scanf("%I64d%I64d%I64d%I64d",&a,&b,&c,&k);
		if((c-b)==(b-a))
		{
			ca=b-a;
		ans=(((a%200907+((k-1)%200907)*(ca%200907)))%200907)%200907;
		//	ans=(a+(k-1)*ca)%200907;
		}
		else if(a*c==b*b)
		{
			bi=(c/b);
			ans=(a*modPow(bi,k-1))%200907;
		}
		printf("%I64d\n",ans);
	}
	return 0;
}






  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值