洛谷P1965 转圈游戏

https://www.luogu.org/problem/show?pid=1965

 

快速幂

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<queue>
#include<cstring>
#include<cmath>
using namespace std;
long long n,m,k,x;
long long ans;
void fastlow(long long a,long long b)
{
    ans=1;
    while(b)
    {
        if(b%2)    ans=(ans*a)%n;
        b/=2;a=(a*a)%n;
    }
    return ;
}
int main()
{
    scanf("%lld%lld%lld%lld",&n,&m,&k,&x);
    m=m%n;
    fastlow(10,k);
    ans=(ans*m)%n;
    ans=(ans+x)%n;
    cout<<ans<<endl;
    return 0;
} 

 

posted @ 2017-10-17 16:49  浪矢-CL  阅读(164)  评论(0编辑  收藏  举报