#include <stdio.h>
#include <iostream>
#include <cmath>
#include <cstring>
using namespace std;
int main(){
int n;
while(cin>>n)
{
int x,f;x=0;
f=1;
do
{
if(f<=n) f*=2;
else f=(f*2-1)%(2*n);
x++;
}while(f!=1);
cout<<x<<endl;
}
return 0;
}
这就是一个规律题。每一次变换1的下标就会乘以2,当超出2*n的时候,就要2*f-2*n-1来确定下标,知道1的下标重新为1.
前几次都是TLE,改了改就是A了。