2^X mod n = 1Time
limit:2000/1000 MS (java/others) Memory limit:65536/32768 K (java/others)
Total submission (s): 14349 Accepted Submission (s): 4438
Problem descriptiongive a number n, find the minimum x (x>0) that satisfies 2^x mod n = 1.
Inputone positive integer on each line, the value of N.
Outputif the minimum x exists, print a line with 2^x mod n = 1.
Print 2^? MoD n = 1 otherwise.
You should replace x and n with specific numbers.
Sample Input
25
Sample Output
2^? MoD 2 = 12^4 MoD 5 = 1
Authorma, Xiao
Sourcezoj Monthly, February 2003
RECOMMENDIGNATIUS.L | We have carefully selected several similar problems for you:2462 2421 2521 1695 2466
#include <stdio.h>int main () {int n;while (~scanf ("%d", &n)) {if (n==1| | n%2==0) printf ("2^? MoD%d = 1\n ", n); Else{int K=2,ncas=1; while (1) { if (k%n==1) break; k=k%n*2; ++ncas; } printf ("2^%d mod%d = 1\n", ncas,n);} }return 0;}
Euler's theorem:for coprime positive integers a and n, there is a ^φ (n) ≡1 mod n. φ (n) refers to the number of positive integers (including 1) that are less than n and n coprime; since 2 is coprime with all odd numbers, so pairs with odd n, there will always be X, making: 2^x =1 (mod n)
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
HDOJ-1395-2^X mod n = 1 "Euler theorem"