HDU 2817 A sequence of numbers
http://acm.hdu.edu.cn/showproblem.php?pid=2817
__int64 pow_mod (__int64 a, __int64 n, __int64 m)快速幂取模函数。
A sequence of numbers
Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 4047    Accepted Submission(s): 
1243
Problem Description
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.
Input
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.
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
Output one line for each test case, that is, the K-th 
number module (%) 200907.
Sample Input
2
1 2 3 5
1 2 4 5
Sample Output
5
16
#include<stdio.h> #include<string.h> #define MOD 200907 __int64 pow_mod (__int64 a, __int64 n, __int64 m) { if(n==0) return 1%m; if(n==1) return a%m; __int64 x=pow_mod(a,n/2,m); __int64 ans=x*x%m; if(n%2==1) ans=ans*a%m; return ans; } int main() { double a,b,c; int t; int k; scanf("%d",&t); while(t--) { scanf("%lf%lf%lf%d",&a,&b,&c,&k); if(a+c==2*b) { __int64 a1=(__int64 )a; __int64 d=(__int64 )(b-a); int ans=(a1%MOD+((k-1)%MOD)*(d%MOD))%MOD; printf("%d\n",ans); } else { __int64 a1=(__int64)a; __int64 t1=(__int64)(a1%MOD); double q1=(b/a); __int64 q2=(__int64)q1; __int64 q=(__int64)q2; __int64 tmp=pow_mod(q,k-1,MOD); int ans=(t1*tmp)%MOD; printf("%d\n",ans); } } return 0; }
 
                    
                
 
                
            
         浙公网安备 33010602011771号
浙公网安备 33010602011771号