# 2 ^ x mod n = 1 [Hangzhou-HDOJ-1395]

Source: Internet
Author: User

/*
2 ^ x mod n = 1
Time Limit: 2000/1000 MS (Java/others) memory limit: 65536/32768 K (Java/Others)
Total submission (s): 11800 accepted submission (s): 3673
Problem description
Give a number N, find the minimum x (x> 0) that satisfies 2 ^ x mod n = 1.

Input
One positive integer on each line, the value of N.

Output
If the minimum x exists, print a line with 2 ^ x mod n = 1.

Print 2 ^? MOD n = 1 otherwise.

You shoshould replace X and N with specific numbers.

Sample Input
2
5

Sample output
2 ^? MoD 2 = 1
2 ^ 4 mod 5 = 1

*/
# Include <stdio. h>
Int main (){
Int I, j, N, S;
While (~ Scanf ("% d", & N )){
If (n = 1 | n % 2 = 0) printf ("2 ^? MoD % d = 1 \ n ", N );
Else {
_ Int64 S = 1;
Int I;
For (I = 1; I ++ ){
S * = 2;
S % = N; // The value of controlling S is within a certain range, and N is obtained after multiplying 2.
If (S = 1) {// If (S % N = 1)
Break;
}

}
Printf ("2 ^ % d mod % d = 1 \ n", I, n );
}
}
Return 0;
}

Related Keywords:

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

## A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

• #### Sales Support

1 on 1 presale consultation

• #### After-Sales Support

24/7 Technical Support 6 Free Tickets per Quarter Faster Response

• Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.