We are to determine the number of primitive roots modulo p. Actually the problem statement says: "Given a prime p, a primitive root g is an integer x (1 ≤ x < p) such that none of integers x - 1, x^2 - 1, ..., x^{p-2} - 1 are divisible by p, but x^{p-1} - 1 is." That's essentially the definition: g is a primitive root modulo p if the order of g modulo p is exactly p-1, meaning g^{p-1} ≡ 1 mod p, and for any smaller positive exponent d < p-1, g^d ≠ 1 mod p. However the condition they've written: "none of integers x - 1, x^2 - 1, ..., x^{p-2} - 1 are divisible by p, but x^{p-1} - 1 is." That's correct.
Thus we need to count the number of primitive roots modulo p, which is a known result: for a prime p, the number of primitive roots is φ(p-1), where φ is Euler's totient function. Since p is prime, p-1 can be factorized. So the answer is φ(p-1). However, need to check: The condition says "x is an integer (1 ≤ x < p)" so it's numbers from 1 to p-1. Primitive root cannot be 0, obviously. Also note that 1 is never a primitive root except for p=2? But p>=2 prime. For p=2, primitive root? p-1=1, order must be 1, but they say "none of x-1, ... x^{p-2} - 1 divisible by p", but p-2 = 0? Actually if p=2, then p-2 = 0, so the list from x^1-1? Wait careful: The list: x-1, x^2-1, ..., x^{p-2}-1. If p=2, then p-2 = 0, so the list includes up to x^0-1? But x^0 is 1, so x^0-1 = 0 which is divisible by p? Not sure. Let's parse: "none of integers x - 1, x^2 - 1, ..., xp - 2 - 1 are divisible by p, but xp - 1 - 1 is." They probably meant x^{p-2} - 1. For p=2, p-2 = 0, so the list includes x^{0} - 1? That's 0, which is divisible by 2. So 1 wouldn't be a primitive root if we follow strictly. However, usually primitive root modulo 2: 1 is a primitive root because the multiplicative group mod 2 is trivial (only 1). But definition often says for prime p, primitive root exists when p=2,3,...; For p=2, the group size is 1, and 1 is a primitive root. However, many number theory definitions consider primitive roots modulo n for n = 2,4, p^k, 2p^k. For prime 2, 1 is a primitive root. But the given condition with exponents up to p-2 would be problematic for p=2, because p-2=0, no condition? Actually they say "none of ... are divisible by p". If the list is empty, then it's vacuously true. So 1 would satisfy the "none" part. Then x^{p-1} - 1 = x^1 - 1; For x=1, 1^1 - 1 = 0 divisible by 2, so condition holds. So 1 is primitive root modulo 2? That's consistent with standard definition? Actually standard primitive root for prime p: an integer g such that its order modulo p is p-1. For p=2, p-1=1, and order of 1 is 1, so yes 1 is a primitive root modulo 2. So answer for p=2 should be φ(1)=1. But the problem input constraints: p from 2 to <2000, prime. So p=2 is possible. Then answer is φ(1)=1. But let's check: p=2, integers 1 ≤ x < 2, only x=1. Check condition: x-1? That's 0 divisible by 2. But the condition says "none of ... are divisible by p". However x-1 = 0 divisible by 2, so that would disqualify 1. But wait, the list "x - 1, x^2 - 1, ..., x^{p-2} - 1" for p=2: p-2 = 0, so the list is from x^1 - 1? Actually they wrote "x - 1, x2 - 1, ..., xp - 2 - 1". I'm pretty sure they meant: x^1 - 1, x^2 - 1, ..., x^{p-2} - 1. But if p=2, then the exponent list would be from 1 to p-2 = 0, which is decreasing? Usually they'd say "none of x^1 - 1, x^2 - 1, ..., x^{p-2} - 1 are divisible by p". For p=2, the range 1 to 0 is empty, so no conditions. So we need to interpret correctly. Many competitive programming problems for primitive root counting use φ(p-1). So answer is φ(p-1). For p=2, φ(1)=1. So that's likely correct.
Thus the solution is straightforward: Given prime p, compute Euler's totient of p-1. Need to output that number.
But wait, is there any nuance? Possibly they might count primitive roots in the range 1 <= x < p, which is standard. The number of primitive roots modulo a prime p is φ(p-1). So we can compute that.
We need to implement for p up to 1999 (since <2000). So p-1 up to 1998. Compute φ(n) for n = p-1.
Implementation: Factorize n (<=1998). Simple: iterate i from 2 to sqrt(n), divide out factors, compute φ as n * product (1 - 1/p) for each distinct prime factor.
Edge: p=2 => n=1. φ(1) is 1 by convention. But careful: Euler's totient φ(1)=1. Indeed number of integers 1 <= k <= 1 that are coprime to 1 is 1? Actually φ(1)=1 by definition. So output 1.
Check examples: p=3 => p-1=2, φ(2)=1, matches. p=5 => p-1=4, φ(4)=2, matches.
Thus answer is φ(p-1). Implementation is trivial.
But let's confirm the statement: "The cows have just learned what a primitive root is! Given a prime p, a primitive root is an integer x (1 ≤ x < p) such that none of integers x - 1, x2 - 1, ..., xp - 2 - 1 are divisible by p, but xp - 1 - 1 is." Possibly the image shows exponents: x^2, x^{p-2}, x^{p-1}. So yeah.
Thus solution is simple.
Now we need to produce final answer: implement reading p, compute p-1, compute φ(p-1), output.
But wait: In some definitions, the number of primitive roots modulo p is φ(p-1) because the multiplicative group modulo p is cyclic of order p-1 and the number of generators of a cyclic group of order n is φ(n). So yes.
Thus answer.
Now let's verify with a few other primes: p=7 => p-1=6, φ(6)=2, indeed primitive roots modulo 7 are 3 and 5. So output 2. p=11 => p-1=10, φ(10)=4, primitive roots are 2,6,7,8? Actually 2,6,7,8 indeed 4. Good.
So the answer is correct.
Now we should consider if there is any trick: p can be up to 1999, so p-1 max 1998, which is small. We can compute φ by iterating from 1 to p-1 and counting numbers coprime, but better to factor.
But both are fine.
Thus solution.
Now final answer code: in C++ perhaps.
Pseudo:
int p;
cin >> p;
int n = p-1;
int result = n;
int temp = n;
for (int i=2; i*i <= temp; ++i) {
if (temp % i == 0) {
while (temp % i == 0) temp /= i;
result -= result / i;
}
}
if (temp > 1) result -= result / temp;
cout << result << endl;
That's it.
But careful: n might be 1. The loop won't run, temp=1, then after loop temp>1? No, temp=1, skip, output result = n = 1. Works.
Thus final.
Now the problem might require more caution: The cows definition: "none of integers x - 1, x^2 - 1, ..., x^{p-2} - 1 are divisible by p, but x^{p-1} - 1 is." That condition would also exclude the case where x=1 because x-1=0 divisible by p, so 1 would not be considered a primitive root for p>2. For p=2, as argued, the list might be empty. So φ(p-1) still matches? Let's check p=3: primitive roots: 2 only, 1 is not primitive because 1^1-1=0 divisible by 3? Actually 1-1=0 divisible by 3? 0 divisible by any number, so condition fails: x-1=0 divisible by p? For p=3, x=1: x-1=0 which is divisible by 3, so fails. So primitive roots are those with order exactly p-1. For p=3, order of 2 is 2, works; order of 1 is 1, not p-1, so not primitive. So φ(2)=1 matches. Good. For p=2: there is only 1; its order is 1, p-1=1, so it is primitive. The condition: list from x^1-1? Actually p-2=0, so the list is empty? Then the condition is vacuously true for "none are divisible". Then check x^{p-1} - 1 = 1^1-1=0 divisible by 2, so true. So 1 qualifies. So φ(1)=1 matches. So it's consistent.
Thus answer is φ(p-1).
Now confirm with p=2: p-1=1, φ(1)=1.
Given constraints p up to <2000, p prime. So code.
Thus final answer.
But what about p=1999? p-1=1998, factor: 1998 = 2 * 3^3 * 37? Actually 1998 = 2 * 999 = 2 * 3 * 333 = 2 * 3 * 3 * 111 = 2 * 3^2 * 111 = 2 * 3^2 * 3 * 37 = 2 * 3^3 * 37. So φ(1998)=1998 * (1-1/2)(1-1/3)(1-1/37)=1998 * 1/2 * 2/3 * 36/37 = 1998 * (1/2)(2/3)(36/37) = 1998 * (1236)/(2337) = 1998 * (72)/(222) = simplify: 1998/222 = 9? Actually 222*9=1998, yes 1998/222=9, then times 72 = 648? Let's compute: 1998 * 72 / 222 = (1998/222)72 = 972=648. So answer 648. That's plausible.
Thus implementation is easy.
Therefore, final output.
But the problem might be from USACO? Actually the cows are typical. So we produce answer.
Now I'll produce the final solution explanation.
Also we need to ensure we output on a single line.
Thus final response: code with φ(p-1).
We should provide in Python? The user didn't specify language but typical solutions in C++. I can provide in multiple languages.
Since I'm ChatGPT, I will provide a solution in C++.
Will include comment.
Now produce final answer.
```cpp
#include
using namespace std;
int main() {
int p;
cin >> p;
int n = p - 1;
int phi = n;
int m = n;
for (int i = 2; i * i <= m; ++i) {
if (m % i == 0) {
while (m % i == 0) m /= i;
phi -= phi / i;
}
}
if (m > 1) phi -= phi / m;
cout << phi << endl;
return 0;
}