#include<iostream>
#include<string>
using namespace std;
int Cycle(int u,int d)
{
int count=0;
int hash[10100],latest[10010];
memset(hash,0,sizeof(hash));
memset(latest,0,sizeof(latest));
while(u%d)
{
count++; //位数
while(u<d)
u*=10;
int tmp=u/d;
if(hash[u]) //出现循环
return count-latest[u]; //减去上次该数出现位置
hash[u]=1;
latest[u]=count;
u-=tmp*d; //余数
}
return 0;
}
int main()
{
int max=0;
int ans;
for(int i=1;i<1000;i++)
{
int digit=Cycle(1,i);
if(digit>max)
{
max=digit;
ans=i;
}
}
cout<<ans<<endl;
return 0;
}
Answer:
| 983 |