【NOIP 2013 DAY.1】T1 转圈游戏【codevs 3285】
易得出答案 (m*(10^k)+x)%n
处理10^k时要用到快速幂。
同时注意每部取%.
#include <cstdio>
typedef long long LL;
int m,n,k,x;
LL qmul(int p,int k)
{
LL temp=p,s=1;
while(k!=0)
{
if(k%2==1)
s=(s*(temp%n))%n;
temp=(temp*temp)%n;
k=k/2;
}
return s;
}
int main()
{
freopen("circle.in","r",stdin);
freopen("circle.out","w",stdout);
scanf("%d%d%d%d",&n,&m,&k,&x);
printf("%I64d",(m*qmul(10,k)+x)%n);
return 0;
}