Link : Problem
Can someone please explain(in simple words) why we need to take only numbers that are coprime with n, I read the editorial but still can't fully understand the proof that why a non coprime number will give prod%n != 1
# | User | Rating |
---|---|---|
1 | tourist | 3993 |
2 | jiangly | 3743 |
3 | orzdevinwang | 3707 |
4 | Radewoosh | 3627 |
5 | jqdai0815 | 3620 |
6 | Benq | 3564 |
7 | Kevin114514 | 3443 |
8 | ksun48 | 3434 |
9 | Rewinding | 3397 |
10 | Um_nik | 3396 |
# | User | Contrib. |
---|---|---|
1 | cry | 167 |
2 | Um_nik | 163 |
3 | maomao90 | 162 |
3 | atcoder_official | 162 |
5 | adamant | 159 |
6 | -is-this-fft- | 158 |
7 | awoo | 155 |
8 | TheScrasse | 154 |
9 | Dominater069 | 153 |
10 | nor | 152 |
Link : Problem
Can someone please explain(in simple words) why we need to take only numbers that are coprime with n, I read the editorial but still can't fully understand the proof that why a non coprime number will give prod%n != 1
Name |
---|
Consider a number x such that gcd(x, n) = L > 1.
Suppose that there exists an integer k such that
kx ≡ 1 (mod n)
kx $$$-$$$ 1 ≡ 0 (mod n)
Then there exists an integer d such that:
kx $$$-$$$ 1 = nd (since kx $$$-$$$ 1 is divisible by n)
We obtain that:
kx $$$-$$$ nd = 1
That is, it is a Diophantine equation of the form kx + ($$$-$$$ d) * n = 1
That is, we have reduced it to the form:
ax + bn = c, where a = k; b = $$$-$$$ d; c = 1.
It is known that if c is not divisible by gcd(x; n), then such an equation has no solutions. In our case gcd(x, n) = L > 1 => 1 is not divisible by L, whence c is not divisible by gdc(x; n)
Contradiction.
Proof of the fact above and information about Diophantine equation you can find here:
Emaxx: http://e-maxx.ru/algo/diofant_2_equation (on russian)
Translated Emaxx: https://cp-algorithms.com/algebra/linear-diophantine-equation.html (on english)
just out of curiosity, Do you have any link or proof that shows:
Yes, of course. I've updated the post above. There are now links
Let's denote k as gcd(x , n). The equation ax + bn = c can also be written as k * (a * x / k + b * n / k) = c. Which means that k and (a * x / k + b * n / k) are pair divisors of c. In other words, k divides c.
got it, thanks
We can use the fact that: (a * n) % (a * m) = a * (n % m).
Since x % y = x — [x / y] * y, where [...] means integer division, we can replace x with a * n and y with a * m: (a * n) % (a * m) = (a * n) — [(a * n) / (a * m)] * (a * m) = (a * n) — [n / m] * (a * m) = a * (n — [n / m] * m) = a * (n % m).
Let's name the product that we have to find with P. Then, we have P % n = 1. Using the above observation, it means that there exists k, a common divisor for P and n, for which he have P % n = k * ((P / k) % (n / k)) = 1. Which means the biggest k must be 1. In other words, the greatest common divisor for P and n is 1 (gcd(P , n) = 1). This also means that the numbers we choose to be a part of P must be coprime with n (else gcd(P , n) would be bigger).
thanks, this is exactly what I was looking for