Hi guys. I started practicing CSES problemset but I am stuck in the problem below.
https://cses.fi/problemset/task/1082
How to deal with cases like n>10e6?
No need for a straight up answer just a hint
| # | User | Rating |
|---|---|---|
| 1 | Benq | 3676 |
| 2 | Kevin114514 | 3659 |
| 3 | jiangly | 3640 |
| 4 | turmax | 3450 |
| 5 | tourist | 3408 |
| 6 | strapple | 3360 |
| 7 | Um_nik | 3354 |
| 8 | squareOf105 | 3348 |
| 9 | maroonrk | 3312 |
| 10 | idontwannadothis…e | 3191 |
| # | User | Contrib. |
|---|---|---|
| 1 | Qingyu | 155 |
| 2 | nik_exists | 151 |
| 3 | maspy | 149 |
| 4 | AmShZ | 145 |
| 5 | Um_nik | 143 |
| 6 | Errichto | 139 |
| 7 | BledDest | 136 |
| 8 | adamant | 135 |
| 9 | maroonrk | 132 |
| 10 | cry | 130 |
Hi guys. I started practicing CSES problemset but I am stuck in the problem below.
https://cses.fi/problemset/task/1082
How to deal with cases like n>10e6?
No need for a straight up answer just a hint
| Name |
|---|



constraint for n is 1<=n<=10e12
In larger cases like n=10e12 where we loop from 1 to 10e12, TLE would be shown.
I used the same approach but it is not working for larger cases of n.
think about how many times you will add x to the answer, when x > 1e6.This value is not too big, so we can bruteforce it.
In this formula, $$$\left\lfloor\dfrac nd\right\rfloor$$$ will be equal for some consecutive $$$d$$$
So we can calculate the left endpoint $$$l$$$ and the right endpoint $$$r$$$, then,
How to calculate $$$l$$$ and $$$r$$$?
You can find some regular patterns. Here is the conclusion: (I'm sorry that I don't know how to prove it)
$$$1$$$ is a left endpoint and for each left endpoint $$$l$$$, the right endpoint $$$r=\left\lfloor \dfrac n{\left\lfloor \dfrac nl\right\rfloor}\right\rfloor$$$.
We can do it in $$$O(\sqrt n)$$$ time.
Here is the code:
I hope this code is correct.