【算法】快速幂运算
【题解】ans=(m*10^k+x)%n,用快速幂计算10^k即可,复杂度为O(log k)。
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
#include<cstdio> long long n,m,k,x,ans; long long quickpow(long long x,long long n,long long k) { long long ans=1; while(n>0) { if(n&1) ans=(ans*x)%k; n>>=1; x=(x*x)%k; } return ans; } int main() { scanf("%lld%lld%lld%lld",&n,&m,&k,&x); printf("%lld",(x+m*quickpow(10,k,n))%n); return 0; }