Small and medium number theory skills: because only one remainder of mod N is required at a time, for the convenience of computer operations, first convert it ..
(A * B) % N = [(a % N) * (B % N)] % N;
(A + B) % N = [(a % n) + (B % N)] % N;
Question: Chinese
Idea: Euler's theorem, but it requires the smallest integer, so we can only use Euler's Theorem to determine the optimization...
For example: 2 ^ K mod n = 1; then K = E (n) must be true; and if such formula is true,Then (2, n) must be of mutual quality (Euler's theorem ),I won't prove it...
Let's try again with brute force. I can't think of a better solution...
Code:
# Include <iostream>
Using namespace STD;
Int main (){
Int N;
While (CIN> N ){
If (N % 2 = 0 | n = 1 ){
Printf ("2 ^? MoD % d = 1 \ n ", N );
Continue;
}
Else {
Int sum = 1;
For (INT I = 1; I ++ ){
Sum * = 2;
If (sum % N = 1 ){
Printf ("2 ^ % d mod % d = 1 \ n", I, n );
Break;
}
Sum = sum % N;
}
}
}
}