51Node 1035----Longest cycle section
The reciprocal 1/k of the positive integer k, which is written as 10 decimal, if it is an infinite loop decimal, there is a cyclic section, which is the longest number in the number of <=n. 1/6= 0.1 (6) The length of the circular section is 11/7= 0. (142857) The length of the circulating section is 61/9= 0. (1) The length of the circulating section is 1Input
Input n (ten <= n <= 1000)
Output
The number of the Countdown cycle section of the output <=n is the longest
Input example
10
Output example
7
The code is as follows:
#include <iostream>#include<algorithm>#include<cstdio>#include<cstring>using namespaceStd;typedefLong LongLL;intlen[1005];inta[1005];intCalcintxx) { inttot=0, pos=0; intx[Ten],y[Ten]; intTmp1,tmp2=1, flag=0; while(1) {TMP1= (tmp2*Ten)/xx; TMP2= (tmp2*Ten)%xx; if(tmp1==0&&tmp2==0) return 0; if(TMP1) flag=1; if(flag) pos++; if(flag&&tot<8) {X[tot]=TMP1; Y[tot++]=TMP2; } for(intI=0; i<tot-1; i++) { if(tmp1==x[i]&&tmp2==Y[i]) { returnpos-i-1; } } }}voidinit () { for(intI=3;i<1005; i++) {Len[i]=Calc (i); } inttmp=-1; intposi=-1; for(intI=3;i<1005; i++) { if(len[i]>tmp) {tmp=Len[i]; Posi=i; } A[i]=posi; }}intMain () {intN; Init (); while(SCANF ("%d", &n)! =EOF) {cout<<a[n]<<Endl; } return 0;}
51Node 1035----Longest cycle section