HDU 2817 A sequence of numbers【水题|快速幂】

求等差或等比数列的第n项

 

 1 #include <iostream>
 2 #include <cstdio>
 3 #include <cstring>
 4 using namespace std;
 5 
 6 const  long long mod = 200907;
 7 
 8  long long Pow( long long x,  long long n) {
 9     if(n == 0) {
10         return 1;
11     }
12     if(n == 1) return x % mod;
13     if(n & 1) return x % mod * Pow(x, n - 1) % mod;
14     else return Pow(x * x % mod, n / 2);
15 }
16 
17 int main() {
18      long long a, b, c, d;
19      long long t;
20     scanf("%lld",&t);
21     while(t--) {
22         scanf("%lld %lld %lld %lld",&a, &b, &c, &d);
23         if(b - a == c - b) {
24              long long x = b - a;
25              long long y = ((a  % mod) + ((( d - 1 ) % mod) * (x % mod)) % mod) % mod;
26             printf("%lld\n", y);
27         } else {
28              long long x = b / a;
29              long long y = (a % mod) * Pow(x % mod, d - 1) % mod;
30             printf("%lld\n", y);
31         }
32     }
33     return 0;
34 }
View Code

 

posted @ 2015-03-24 20:50  悠悠我心。  阅读(94)  评论(0编辑  收藏  举报