On this Friday will take place Topcoder SRM 596.
GL & HF
# | User | Rating |
---|---|---|
1 | tourist | 3985 |
2 | jiangly | 3814 |
3 | jqdai0815 | 3682 |
4 | Benq | 3529 |
5 | orzdevinwang | 3526 |
6 | ksun48 | 3517 |
7 | Radewoosh | 3410 |
8 | hos.lyric | 3399 |
9 | ecnerwala | 3392 |
9 | Um_nik | 3392 |
# | User | Contrib. |
---|---|---|
1 | cry | 169 |
2 | maomao90 | 162 |
2 | Um_nik | 162 |
4 | atcoder_official | 161 |
5 | djm03178 | 158 |
6 | -is-this-fft- | 157 |
7 | adamant | 155 |
8 | Dominater069 | 154 |
8 | awoo | 154 |
10 | luogu_official | 150 |
On this Friday will take place Topcoder SRM 596.
GL & HF
Name |
---|
How to solve the last problem efficiently?
How to solve 1000 div.2?
At first you've to notice that for F(n) be divisible by P, at least one part of the multiplication (n — i²) must be a multiple of P. So we have that n — i² (mod P) = 0 (mod P), so n (mod P) = i² (mod P). It's clear that i must be less than sqrt(n), so we can iterate over all possible i's and for each of them count how many n's exists that are less than some integer A. After some math it's clear that counting this is equal to (A — i²)/P. That's not the complete solution, since we're overcalculating some n's, and this occurs when we have some positive integer j different from i and less than sqrt(n) such that j² (mod P) = i² (mod P). Using an array or a set to mark for each i if i² module P has been already visited is enough.
Just calculate the answer for A being hi and subtract it from A being lo — 1 and you're done.
P.S: To better explain why (A — i²)/P, we know that n (mod P) = i² (mod P) and we can express it as n = i² + P*k. We know that n must be less than A, so i² + P*k < A, so k is actually the number of different solutions. Isolating k, we have:
P*k < A — i²
k < (A — i²)/P
k = floor((A — i²)/P)
My code: http://pastie.org/private/gltsff0nslzgn6cyqdexa
First Thanks for your neat explanation
Second In inequality you say k < (A — i²)/P not k <= (A — i²)/P
So what about if (A — i²)/P is integer like 12 so k<12 but
floor(12) is 12
So in this case k not less than (A — i²)/P but it equal to it
Third I want to learn how to reduce problem to equations like this do you have any advice or a how can I practice on this ?
Thanks
Editorial (complete)