Click to view the topic
At first look at this problem, there is really no train of thought (really ashamed).
And then I saw this paper: Portal
Suppose a cyclic section that requires a positive integer reciprocal is actually the last to solve a minimum x satisfying 10x=1 (mod C)
Tenx≡1(moDC)
If GCD (10,c)!=1, it is clear that there is no solution. If there is a solution, according to Euler's formula, then this solution X|phi (C), so the direct violent enumeration of x is good.
#include <bits/stdc++.h>using namespacestd;intPhiintm) {intAns =m; for(intI=2; i*i<=m; i++) { if(m%i==0) {ans= ans/i * (i-1); while(m%i==0) m/=i; } } if(m>1) ans = ans/m * (M-1); returnans;}intfpintAintNintp) {intR =1; while(n) {if(n&1) R = R * A%p; A= A * A%p; N>>=1; } returnR;}intMain () {intN; CIN>>N; intAns =0, cnt =0; for(intp=7; p<=n; p++)if(__GCD (Ten, p) = =1) { intPHN =Phi (P); for(intI=1; i<=phn; i++) { if(phn%i = =0&& FP (Ten, I, p) = =1) { if(i>CNT) {CNT=i; Ans=p; } Break; } }} cout<< ans <<Endl; return 0;}
x ≡1(moDC)
51nod-1035 Longest Looping section