Coprime Count in a Range
Time limit1sMemory limit128 MB
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 , count how many integers between and , inclusive, are coprime with .
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 . ()
Each test case is one line holding three integers , , separated by spaces. (, )
Output
For each test case print one line in the form Case #x: y, where is the test case number starting from 1 and is how many integers between and , inclusive, are coprime with .
Hint
Among the numbers in , the ones coprime with 2 are .