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.
等比数列或等差数列。。。
1 #include<iostream> 2 #include<cstdio> 3 #include<cstring> 4 #include<cmath> 5 #include<stdlib.h> 6 #include<algorithm> 7 #include<queue> 8 #include<map> 9 using namespace std; 10 #define MOD 200907 11 #define ll long long 12 ll pow_mod(ll a,ll n) 13 { 14 if(n==0) 15 return 1%MOD; 16 ll tt=pow_mod(a,n>>1); 17 ll ans=tt*tt%MOD; 18 if(n&1) 19 ans=ans*a%MOD; 20 return ans; 21 } 22 int main() 23 { 24 int t; 25 scanf("%d",&t); 26 while(t--) 27 { 28 ll a,b,c,k; 29 scanf("%I64d%I64d%I64d%I64d",&a,&b,&c,&k); 30 if(a==b && b==c) 31 { 32 printf("%I64d\n",a%MOD); 33 continue; 34 } 35 if(k==1) 36 { 37 printf("%I64d\n",a%MOD); 38 continue; 39 } 40 if(k==2) 41 { 42 printf("%I64d\n",b%MOD); 43 continue; 44 } 45 if(k==3) 46 { 47 printf("%I64d\n",c%MOD); 48 continue; 49 } 50 ll cnt=b-a; 51 if(c-b==cnt) 52 { 53 ll ans=a+(k-1)*cnt; 54 printf("%I64d\n",ans%MOD); 55 } 56 else 57 { 58 ll q=b/a; 59 printf("%I64d\n",a*pow_mod(q,k-1)%MOD); 60 } 61 } 62 return 0; 63 }