[题目链接]
https://www.luogu.org/problemnew/show/P1965
[算法]
不难看出答案为(x + m10^k) % n
用快速幂求解即可
时间复杂度 :O(log K)
[代码]
#include<bits/stdc++.h> using namespace std; int n,m,k,x; inline int power(int a,int n,int p) { int b = a,res = 1; while (n > 0) { if (n & 1) res = 1ll * res * b % p; b = 1ll * b * b % p; n >>= 1; } return res; } int main() { scanf("%d%d%d%d",&n,&m,&k,&x); printf("%d ",(x + m * power(10,k,n)) % n); return 0; }