HDOJ-1395-2^X mod n = 1 "Euler theorem"

Source: Internet
Author: User

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"

Contact Us

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.