Problems > Coprime to N in a Range

Coprime to N in a Range

Difficulty: 1900 4000 ms 128 MB

number-theory

Count the integers in [L, R] that are coprime with N.

Input: one line with three integers L, R, N.

Output: the count of coprime integers.

Constraints:

  • 1 ≤ L ≤ R ≤ 1012
  • 1 ≤ N ≤ 109

Sample Tests

Input 1
1 10 6
Output 1
3
Input 2
1 1 5
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.