# A. Cows and Primitive Roots

Source: Internet
Author: User
Time limit per test

2 seconds

Memory limit per test

256 megabytes

Input

Standard Input

Output

Standard output

The cows have just learned what a primitive root is! Given a primeP, A primitive root is
An integerX(1 digit ≤ DigitXLatency <latencyP) Such
That none of IntegersXAccept-limit 1, limit,X2 seconds-interval 1, interval..., interval ,...,XPInvalid-limit 2 values-limit 1 are
DivisibleP,XPInvalid-limit 1 partial-limit 1 is.

Unfortunately, computing primitive roots can be time consuming, so the cows need your help. Given a primeP, Help the cows find the number
Of Primitive Roots.

Input

The input contains a single line containing an integerP(2 cores ≤ CoresPLimit <limit 2000 ).
It is guaranteed thatPIs a prime.

Output

Output on a single line the number of Primitive Roots.

Sample test (s) Input
`3`
Output
`1`
Input
`5`
Output
`2`
Note

The only primitive root is 2.

The primitive roots are 2 and 3.

Problem description: This question is to find the maximum number of common, the meaning of the question is X-1, x ^ 2-1 ,..., the maximum common divisor of x ^ (P-2)-1 and P is 1, and x ^ (p-1)-1 can be divisible by P. This question can be simulated, but there is a simpler method on the Internet:

Ferma's theorem is an important theorem in number theory. Its content is: if p is a prime number and (A, P) = 1, then

A ^ P-1) 1_1 (mod p) If P is a prime number and a and P are mutually qualitative, then the remainder of A's (PM) is equal to 1 by the remainder of P.

For this question, we only need to find the number of mutually qualitative numbers with the p-1's, which can satisfy the two conditions. However, we can use the Euler's function to find the number of mutually qualitative numbers with P-1's (first obtain the prime factor for the entire division of the p-1's, then bring the formula)

`#include <iostream>#include <cstdio>#include <cstdlib>#include <cmath>#include <cstring>#include <string>#include<set>#include <algorithm>using namespace std;int gcd(int a, int b){   return b ? gcd(b, a%b) : a;}int main(){   int p,i;    int ans=0;   scanf("%d",&p);   for(i=1; i<p; ++i)   {   if(gcd(p-1, i)==1){ans++;}   }   printf("%d\n",ans);}`
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.