用一般的约瑟夫环会超空间
看到m==2 就可能是找规律
#include<iostream> #include<cmath> using namespace std; int num,down; string s; int main(){ while(cin>>s){ if(s=="00e0") break; num=((s[0]-'0')*10+(s[1]-'0'))*pow(10,s[3]-'0'); down=1; while(down*2<=num){ down<<=1; } cout<<(num-down+1)*2-1<<endl; } return 0; }打表代码
#include<iostream> #include<cmath> using namespace std; const int N=99e6+10; int f[N],num; string s; void init(int x){ f[0]=1; for(int i=1;i<=x;i++) f[i]=(f[i-1]+2)%i; } int main(){ init(99e6+10); for(int i=1;i<20;i++)cout<<i<<" "<<f[i]+1<<endl; return 0; }