标签:
这个题的意思是给你N个序列, 每个序列可能是等比数列也可能是等差数列, 求出数列的第k项, 代码如下:
#include <cstdio> #include <algorithm> #include <cstring> #include <iostream> using namespace std; typedef unsigned long long ULL; ULL a, b, c, k; const ULL mod = 200907; ULL pow_mod(ULL A, ULL B) { ULL res = 1; A = A%mod; while(B > 0) { if(B&1) res = (res*A)%mod; B = B>>1; A = (A*A)%mod; } return res; } int main() { int N; scanf("%d", &N); while(N--) { cin>>a>>b>>c>>k; ULL res; if(a+c == 2*b) //等差数列 { ULL d = c-b; res = (a%mod + ((k-1)%mod)*(d%mod))%mod; } else //等比数列 { ULL q = c/b; res = a*pow_mod(q, k-1)%mod; } cout<<res%mod<<endl; } return 0; }
标签:
原文地址:http://www.cnblogs.com/xingxing1024/p/5267109.html