hdu 2718 A sequence of numbers
题意:
给出a,b,c,k,四个数;由 a,b,c构成一个非递减的等差数列或等比数列;求数列的第k个值;
其中等比数列需要用到快速幂的算法;
#include<stdio.h> #define mod 200907 long long multy(long long q,long long n)//快速幂运算 { long long cnt=n; long long base=q; long long ret=1; while(cnt>0) { if(cnt&1) ret=ret*base%mod; cnt=cnt>>1; base=base*base%mod; } return ret; } int main() { int _case,ans; long long a,b,c,k; scanf("%d",&_case); while(_case--) { scanf("%I64d %I64d %I64d %I64d",&a,&b,&c,&k); //scanf("%lld %lld %lld %lld",&a,&b,&c,&k); if(c-b==b-a) { long long d=(c-b)%mod; ans=(a%mod+(k-1)%mod*d%mod)%mod; //printf("%d\n",ans) } else { long long q=b/a%mod; ans=(a%mod)*multy(q,k-1)%mod; } printf("%d\n",ans); } return 0; }
注意:
用lld输入的时候,Wrang了好多次!!!!!!!!!!!!!!