This page is still under construction.

Parts of this page are still being built. What you see may change.

Coprime Count in a Range

Time limit1sMemory limit128 MB

Summary
Count integers in [A, B] whose greatest common divisor with N is 1 for up to 100 test cases.
Level

Medium6 of 10

Topics
Number theory, Combinatorics
Solved
No attempts yet

Problem

Given a natural number NN, count how many integers between AA and BB, inclusive, are coprime with NN.

Two integers are coprime when the only positive integer that divides both of them is 1. In other words, they are coprime when their greatest common divisor is 1. The number 1 is coprime with every integer.

Input

The first line contains the number of test cases TT. (0<T≤1000 < T \le 100)

Each test case is one line holding three integers AA, BB, NN separated by spaces. (1≤A≤B≤10151 \le A \le B \le 10^{15}, 1≤N≤1091 \le N \le 10^9)

Output

For each test case print one line in the form Case #x: y, where xx is the test case number starting from 1 and yy is how many integers between AA and BB, inclusive, are coprime with NN.

Hint

Among the numbers in [1,10][1, 10], the ones coprime with 2 are 1,3,5,7,91, 3, 5, 7, 9.

Examples1

  1. Example 1

    Input
    2
    1 10 2
    3 15 5
    
    Expected output
    Case #1: 5
    Case #2: 10