CF BUDDY
← Problems·

284A · Cows and Primitive Roots

1400 · implementation, math, number theory

Problem: The cows have just learned what a primitive root is! Given a prime p, a primitive root modp\bmod p is an integer x (1 ≤ x < p) such that none of integers x - 1, x2 - 1, ..., xp - 2 - 1 are divisible by p, but xp - 1 - 1 is.

Unfortunately, computing primitive roots can be time consuming, so the cows need your help. Given a prime p, help the cows find the number of primitive roots modp\bmod p.

Input Format: The input contains a single line containing an integer p (2 ≤ p < 2000). It is guaranteed that p is a prime.

Output Format: Output on a single line the number of primitive roots modp\bmod p.

Note: The only primitive root mod3\bmod 3 is 2.

The primitive roots mod5\bmod 5 are 2 and 3.

Sample Cases

Case 1

Input

3

Output

1

Case 2

Input

5

Output

2

Similar problems

00:00:00
Loading editor…
Welcome! I'm your coding tutor for this problem. Use the chips below to reveal stored hints or get AI feedback on your code. I'll guide you step by step — never giving away the solution.

Sign in to unlock AI tutor feedback