how can I solve this problem? Any hints ? here is the problem link :
# | User | Rating |
---|---|---|
1 | tourist | 3565 |
2 | Benq | 3540 |
3 | Petr | 3519 |
4 | maroonrk | 3503 |
5 | jiangly | 3391 |
6 | ecnerwala | 3363 |
7 | Radewoosh | 3349 |
8 | scott_wu | 3313 |
9 | ainta | 3298 |
10 | boboniu | 3289 |
# | User | Contrib. |
---|---|---|
1 | 1-gon | 199 |
2 | Errichto | 196 |
3 | rng_58 | 194 |
4 | SecondThread | 186 |
4 | awoo | 186 |
6 | Um_nik | 182 |
7 | vovuh | 178 |
8 | Ashishgup | 176 |
9 | antontrygubO_o | 173 |
9 | -is-this-fft- | 173 |
how can I solve this problem? Any hints ? here is the problem link :
Name |
---|
how can I solve this problem? with patience
Any idea or hints ?
how can I solve this problem? look at the editorial
$$$\prod_{i = 1}^N p_j^{\lfloor{\frac M p_j}\rfloor}$$$ if $$$i$$$ is prime else you gotta do some inclusion and exclusion principle instead of subtraction you have to divide.
Let's have $$$f(n, x) = gcd(1, x) * gcd(2, x) * ... gcd(n, x)$$$. Then answer is $$$f(n, 1) * f(n, 2) * ... * f(n, m)$$$
Since $$$g(x) = gcd(a, x)$$$ is multiplicative function over $$$x$$$ then $$$f(x) = f(n, x)$$$ is multiplicative function over $$$x$$$ too. So you can calculate all $$$f(x)$$$ for $$$x$$$ in $$$[1..m]$$$ for $$$O(m)$$$.
kinda like my approach right?
Not really sure how your approach works and implements. But maybe in nutshell they same. I don't mean any inclusion/exclusion, just dp.
This is my approach. I later realised I could do this without inclusion-exclusion. But not sure if this is right.
UPD: AC code
You need just for linear time calculate factorization of all numbers. Click
Noice! That's really a cool algorithm and a cool blog.