hdu 2817 A sequence of numbers——快速幂取模

    xiaoxiao2021-03-25  99

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2817

    快速幂模板题,含有加、减、乘的取模运算都可以先取模再运算。快速幂取模算法网上有很多详细的解释,这里贴一个while版

    #include<iostream> #include<cstdio> using namespace std; #define ll long long const int mod=200907; int qmod(ll a,ll b) { int t=1; a%=mod; while(b) { if(b&1) t=(t*a)%mod; a=(a*a)%mod; b/=2; } return t; } int main() { ll a,b,c,k,res; int T; cin>>T; while(T--) { cin>>a>>b>>c>>k; if(c-b==b-a) { res=a%mod+((k-1)%mod)*((b-a)%mod); res%=mod; } else { res=qmod(b/a,k-1); res=(a%mod)*res%mod; } cout<<res<<endl; } }

    转载请注明原文地址: https://ju.6miu.com/read-22630.html

    最新回复(0)