#include<algorithm> #include<iostream> #include<cstring> #include<cstdio> using namespace std; long long read(){ long long a=0,b=1; char ch=getchar(); while(ch<'0'||ch>'9'){ ch=getchar(); } if(ch=='-'){ b=-1; ch=getchar(); } while(ch>='0'&&ch<='9'){ a=a*10+ch-'0'; ch=getchar(); } return a*b; } int main(){ freopen("joseph.in","r",stdin); freopen("joseph.out","w",stdout); long long n,m; n=read(),m=read(); long long i; for(i=1;i<=(n-1)/m;i*=m); printf("%lld",((n-i)/(m-1)*m-1)%n+1); return 0; }
不开long long就......