首页 > 代码库 > hdu_2817_高速幂

hdu_2817_高速幂

水~

#include <cstdio>
#include <iostream>
#include <cstring>
#include <algorithm>
#include <set>
#include <queue>
#include <map>
using namespace std;
#define MAX(x,y) (((x)>(y))?(x):(y))
#define MIN(x,y) (((x)<(y))?(x):(y))
#define N 500010
#define pi acos(-1.0)
#define mod 200907
#define inf 100000000
typedef long long ll;
typedef unsigned long long ull;
ll powmod(ll a,ll n){
    ll ans=1;
    ll tmp=a;
    while(n){
        if(n&1){
            ans*=tmp;
            ans%=mod;
        }
        n>>=1;
        tmp*=tmp;
        tmp%=mod;
    }
    return ans;
}

int main(){
    int t;
    scanf("%d",&t);
    ll a,b,c,n,ans;
    while(t--){
        scanf("%lld%lld%lld%lld",&a,&b,&c,&n);
        if(b*2==a+c){
            ans=(a+(n-1)*(b-a)%mod)%mod;
        }
        else {
            ans=a*powmod(b/a,n-1)%mod;
        }
        printf("%I64d\n",ans);
    }
    return 0;
}

<script type="text/javascript"> $(function () { $(‘pre.prettyprint code‘).each(function () { var lines = $(this).text().split(‘\n‘).length; var $numbering = $(‘
    ‘).addClass(‘pre-numbering‘).hide(); $(this).addClass(‘has-numbering‘).parent().append($numbering); for (i = 1; i <= lines; i++) { $numbering.append($(‘
  • ‘).text(i)); }; $numbering.fadeIn(1700); }); }); </script>

hdu_2817_高速幂