题目1442:A sequence of numbers

题目1442:A sequence of numbers

时间限制:1 秒

内存限制:128 兆

特殊判题:

提交:1396

解决:309

题目描述:

Xinlv wrote some sequences on the paper a long time ago, they might be arithmetic or geometric sequences. The numbers are not very clear now, and only the first three numbers of each sequence are recognizable. Xinlv wants to know some numbers in these sequences, and he needs your help.

输入:

The first line contains an integer N, indicting that there are N sequences. Each of the following N lines contain four integers. The first three indicating the first three numbers of the sequence, and the last one is K, indicating that we want to know the K-th numbers of the sequence.

You can assume 0 < K <= 10^9, and the other three numbers are in the range [0, 2^63). All the numbers of the sequences are integers. And the sequences are non-decreasing.

输出:

Output one line for each test case, that is, the K-th number module (%) 200907.

样例输入:
2
1 2 3 5
1 2 4 5
样例输出:
5
16
水水更健康~~
//1442
#include<cstdio>
const int MOD = 200907;

int
main(void)
{
	int N;
	while(~scanf("%d",&N))
	{
		while(N--)
		{
			long long arr[4];
			int k;
			long long ans = 0;
			scanf("%lld%lld%lld%d",&arr[1],&arr[2],&arr[3],&k);

			if((arr[3]-arr[2])==(arr[2]-arr[1]))//等差
			{
				long long m = arr[3]-arr[2];
				ans = arr[1];
				ans = (ans + ((k-1)%MOD)*(m%MOD))%MOD;//公式
			}
			else if(arr[3]%arr[2]==0 && arr[2]%arr[1] ==0 
				&& arr[3]/arr[2]==arr[2]/arr[1])//等比 
			{
				long long  m = arr[3]/arr[2];
				ans = arr[1];
				k--;
				while(k>0)
				{
					if(k & 1)//快速幂 
					{
						ans = (ans*m)%MOD;//对过程取模 
					}
					m = (m*m)%MOD;
					k /= 2;
				}
			}
			printf("%d\n",ans%MOD);
		}
	}
	return 0;
} 


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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值