转圈游戏

传送门:https://www.luogu.org/problemnew/show/P1965

每次走m步,一共走10^k步,从x处出发,最终位置是(m*10^k+x)%n

代码

#include<cstdio>
using namespace std;
#define ll long long int
inline ll read()
{
    static char ch;
    while((ch = getchar()) < '0' || ch > '9');
    int ret = ch - 48;
    while((ch = getchar()) >= '0' && ch <= '9')
        ret = ret * 10 + ch - 48;
    return ret;
}
ll n,m,k,x;
ll quickPow(ll a,ll b,ll p)
{
    ll ret = 1;
    while(b)
    { 
        if(b%2==1) ret = ret * a % p;
        a = a * a % p;
        b /= 2;
    }
    return ret;
}
int main()
{
    n = read();
    m = read();
    k = read();
    x = read();
    printf("%lld",(m * quickPow(10,k,n) + x)%n);
    return 0;
}
原文地址:https://www.cnblogs.com/peppa/p/9843707.html