Hi, I'm stuck on this problem, but I'm unable to find a solution which I could understand. Can someone explain it to me
# | User | Rating |
---|---|---|
1 | tourist | 4009 |
2 | jiangly | 3823 |
3 | Benq | 3738 |
4 | Radewoosh | 3633 |
5 | jqdai0815 | 3620 |
6 | orzdevinwang | 3529 |
7 | ecnerwala | 3446 |
8 | Um_nik | 3396 |
9 | ksun48 | 3390 |
10 | gamegame | 3386 |
# | User | Contrib. |
---|---|---|
1 | cry | 166 |
2 | maomao90 | 163 |
2 | Um_nik | 163 |
4 | atcoder_official | 161 |
5 | adamant | 159 |
6 | -is-this-fft- | 158 |
7 | awoo | 157 |
8 | TheScrasse | 154 |
9 | nor | 153 |
9 | Dominater069 | 153 |
Hi, I'm stuck on this problem, but I'm unable to find a solution which I could understand. Can someone explain it to me
Name |
---|
click
uh sorry, but the problem tells us to compute the sum of sum of divisors of i for i = 1 -> n, not the sum of divisors of n only
Then may be Dirichlet's Formula, Though I don't understand it properly. So, can't explain more.
Well, I did google this and I can't come up with a O(sqrt(n)) solution or less
In case you haven't figured out yet
For a divisor d, d can appear floor(n, d) times as divisor of all number 1-n. E.g. n=100, d=2 then 2 can appear 50 times as divisor
We also know that every divisor from (floor(n, d+1)+1, floor(n, d)) can appear d times. E.g. n=100, d=2 then every divisor from (34, 50) can appear 2 times.
Can you see O(sqrt(n)) approach from this?
thanks, I coded it and it worked, turns out it's not that hard ....
We can see that the sum is equivalent to
It's easy to see that
has only O(sqrt(N)) distinct values, so we can group together ranges that has the same division value and use A.P sum.
In case you're wondering why the sum has only $$$O(\sqrt{n})$$$ distinct values:
There are 2 cases for $$$\left \lfloor{\frac{n}{i}}\right \rfloor$$$.
In total, we have at most $$$2 \cdot \sqrt{n} = O(\sqrt{n})$$$ distinct values.
thanks for helping me out :D
which algo is this ? Can i know ?
Common sense.
We can't run this in O(n). The value of n 1e12