"Poj1284-primitive Roots" Euler function-the number of primitive roots of odd primes

Source: Internet
Author: User

http://poj.org/problem?id=1284

Test instructions: Given an odd prime p, the number of the original root of P is obtained.

Original root: {(xi mod p) | 1 <= i <= p-1} is equal to {1, ..., p-1}, then x is the original root of P.

Conclusion: The number of the original root of the singular prime P is phi (P-1).

Prove:

for the given prime number p, the first thing to be clear: the Motone of P must be present (this has been proved by Euler, this is not mentioned here), therefore, it may be possible to set one of the meta-Root is A0 (1<=a0<=p-1) according to the definition of the topic, A0^i (1<=i <=p-1) mod p values are different, and then by P is the prime number, the contact Fermat small theorem: q^ (p-1) mod p=1; (1<=q<=p-1) (this is useful below) proves that if B is a different from a motone of p, may make B and A0 ^t about P congruence, then there is bound to be gcd (t,p-1) = 1, that is T and P-1 coprime, and vice versa; Proof: if D=GCD (t,p-1) >1, T=k1*d,p-1=k2*d, then Fermat (a0^ (k1*d)) ^K2 MoD p= ( a0^ (k2*d) ^ (K1) mod p= (a0^ (p-1)) ^ (K1) mod p=1 again by b=a0^t (mod p), combined with the above formula: (a0^ (k1*d)) ^k2 mod n=b^k2 mod p=1; b^0 mod p=1, so B^0=B^K2 (mod p), so b^i mod P's cycle section =k2<p-1, so that B is not meta-root; re-certification, if D=GCD (t,p-1) = 1, that is T and P-1 coprime, then B is necessarily motone; P-1, making b^j=b^i (mod p), i.e. a0^ (j*t) =a0^ (i*t) (mod p), is a meta-root by A0, that is, the length of the loop section of A0 is (p-1), (p-1) | (I*t-j*t), (p-1) | t* (I-J), due to P with T coprime, so (p-1) | (I-J), but according to the hypothesis, 0<i-j<p-1, draw the contradiction, the conclusion is proved; by the above two proofs b=a0^t (mod p), is a meta-root of the necessary and sufficient conditions is T and P-1 coprime, all of these T's total number is Phi (p-1);

Reference from http://poj.org/showmessage?message_id=158630

The proof was very witty, and I didn't even think of splitting p-1 and T. Remember this idea of splitting. Note: Fermat is the Fermat theorem.

Because the data range of the topic is relatively small, so I did not use Euler sieve directly decomposition factorization.

#include <cstdio>#include<cstdlib>#include<cstring>#include<iostream>using namespaceStd;typedefLong LongLL; ll Eular (ll x) {ll ans=x,k=2;  while(x!=1)    {        if(x%k==0) {ans/=K; Ans*= (K-1); }         while(x%k==0) x/=K; K++; }    returnans;}intMain () {//freopen ("a.in", "R", stdin); //freopen ("A.out", "w", stdout);LL x;  while(SCANF ("%i64d", &x)! =EOF) {printf ("%i64d\n", Eular (X-1)); }    return 0;}
View Code

"Poj1284-primitive Roots" Euler function-the number of primitive roots of odd primes

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.