http://icpc.upc.edu.cn/problem.php?cid=1685&pid=0
#include<cstdio>
using namespace std;
int n,m,x,k,kk,i,j,ans=1;
int main()
{
scanf("%d%d%d%d",&n,&m,&k,&x);
kk=10;
while (k){
if (k&1)ans=ans*kk%n;
kk=kk*kk%n;
k>>=1;
}
printf("%d\n",(x+m*ans)%n);
}