Title Description
For a given x, find the smallest positive integer y that makes x^y%mod = 1 , where mod = 790660457.
Input
Multiple input groups (up to 50000 groups)
One x (0 < x < MoD) per group
Output
First test the number of groups, and then output the corresponding minimum positive integer y, see example
Sample input
13
Sample output
Case #1:1Case #2:790660456
Tips
Fast power of Fermat theorem
A conclusion from the Fermat theorem that this y is bound to be a mod-1 factor.
//asimple #include <bits/stdc++.h>#defineINF 0XFFFFFFF#defineMoD 790660457#defineSwap (a,b,t) T = A, a = B, b = t#defineCLS (A, V) memset (A, V, sizeof (a))#defineDebug (a) cout << #a << "=" << a <<endl#defineABS (x) x<0?-x:x#defineSRD (a) scanf ("%d", &a)#defineSRC (a) scanf ("%c", &a)#defineSRS (a) scanf ("%s", a)#defineSrdd (A, b) scanf ("%d%d", &a, &b)#defineSRDDD (a,b,c) scanf ("%d%d%d", &a, &b, &c)#definePRD (a) printf ("%d\n", a)#definePrdd (b) printf ("%d%d\n", A, B)#definePRS (a) printf ("%s\n", a)#definePRC (a) printf ("%c", a)using namespaceStd;typedefLong Longll;Const intMAXN =1001;intN, M, num, T, K, Len, ans, sum;intDP[MAXN];
Find a factor
voidsolve () {Len=0; ll Num= mod-1; for(intI=1; i*i<=num; i++) { if(num% i = =0) {Dp[len++] =i; if(num/i!=i) {Dp[len+ +] = num/i; }}} sort (DP, DP+len);} //Fast power ll Qpow (ll A, LL B, ll MD) {ll ans=1; while(b) {if(B &1) ans = ans * a%MD; A= A * A%MD; b= b >>1; } returnans;} voidinput () {intCI =0; Solve (); while( ~SRD (n)) {printf ("Case #%d:", ++ci); for(intI=0; i<len; i++) { if(Qpow (n, dp[i], mod) = =1) {PRD (dp[i]); Break; } } }} intMain () {input (); return 0;}
The theory of first-involved