Count integers in a range that are primitive roots modulo a given prime.
Problem
You are given a prime number and a range of integers. Your task is to count how many integers in the range are primitive roots modulo .
An integer is called a primitive root modulo if its powers generate all non-zero residues modulo .
In other words, the values contain every number from $1p-1$ exactly once.
Return the count of numbers in the given interval that satisfy this property.
Input Format
- A prime integer
- A range of integers
The exact input format is the standard one used by the platform.
Output Format
Output a single integer — the number of primitive roots modulo that lie in the given range.
Constraints
- is prime
- The range bounds are integers
- A number can only be a primitive root modulo if it is coprime to
The exact official limits are not provided in the source metadata.
Example 1
Input
p = 7 l = 1 r = 6
Output
2
Explanation
The primitive roots modulo 7 are 3 and 5, so there are 2 numbers in the range [1, 6].
Example 2
Input
p = 11 l = 1 r = 10
Output
4
Explanation
The primitive roots modulo 11 are 2, 6, 7, and 8.
Premium problem context
Unlock deeper context for this problem
Premium adds guided hints, editorial links, similar variants, discussion resources, and concept maps so you can understand why a problem matters, not just solve it once.