Problems > Euler's Totient

Euler's Totient

Difficulty: 1600 3000 ms 128 MB

math number-theory

Print φ(N): how many integers in [1, N] are coprime with N.

Input: one integer N.

Output: φ(N).

Constraints:

  • 1 ≤ N ≤ 1012

Sample Tests

Input 1
9
Output 1
6
Input 2
1
Output 2
1

Read the Editorial

Discussion (opens after you solve — no spoilers before)

No comments yet.

Submit Your Solution

Log in or create a free account to run and submit code.