n,x=input();exec('k=m=1;'+'x-=(x%k<m%k)*x/k;m*=k*k;k+=1;'*x)*n;print x
3,100
8
The brand new service which powers Ideone!
Widget for compiling and running the source code in a web browser!