思路:
若a和b互素的话,则b*t+a和b一定互素
用周期性做就好了
//By SiriusRen #include <cstdio> using namespace std; int s[1000050],m,k; int gcd(int a,int b){return b?gcd(b,a%b):a;} int main(){while(~scanf("%d%d",&m,&k)){int tp=0;for(int i=1;i<=m;i++)if(gcd(m,i)==1)s[tp++]=i;printf("%d\n",k%tp?(k/tp)*m+s[k%tp-1]:(k/tp-1)*m+s[tp-1]);} }