Can anyone explain how to solve this 687B - Remainders Game . I don't understand how to come with ideas for such problems and I did not understand the editorial well.
№ | Пользователь | Рейтинг |
---|---|---|
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 |
Страны | Города | Организации | Всё → |
№ | Пользователь | Вклад |
---|---|---|
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 |
Can anyone explain how to solve this 687B - Remainders Game . I don't understand how to come with ideas for such problems and I did not understand the editorial well.
Название |
---|
If you know xmodc1,xmodc2,...,xmodcn then you can find out xmodlcm(c1,c2,...,cn) if the given values are not self-contradictory(eg. xmod2=0 and xmod4=1). Conversely, if you know xmodlcm(c1,c2,...,cn) you can find each of the given n values. So first find xmodlcm(c1,c2,...,cn) and this would retain all the information. Now, if k divides lcm(x1,x2,...,xn) you can easily find xmodk otherwise you can't.
The editorial proves that all you have to do is check whether $$$k \mid \text{lcm}(c_1, \dots, c_n)$$$. This is equivalent to saying $$$\gcd(k, \text{lcm}(c_1, \dots, c_n)) = k$$$. But we can calculate the left side very easily since $$$\gcd(k, \text{lcm}(c_1, \dots, c_n)) = \text{lcm}(\gcd(k, c_1), \dots, \gcd(k, c_n))$$$. The time complexity will be $$$O(n(\log(C) + \log(K)))$$$. Also there will not be overflow because the intermediate value will always be $$$\leq k$$$.
These identities hold because if you think of an integer's prime factorization as a multiset, $$$\mid$$$ corresponds to $$$\subseteq$$$, $$$\gcd$$$ corresponds to $$$\cap$$$, and $$$\text{lcm}$$$ corresponds to $$$\cup$$$