Problem : https://codeforces.me/contest/1538/problem/D
Solution Link : https://codeforces.me/contest/1538/submission/119077891
Can anyone explain why I am getting TLE on test 6 for this solution?
| # | 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 | 153 |
| 2 | nik_exists | 151 |
| 3 | maroonrk | 150 |
| 4 | maspy | 149 |
| 5 | AmShZ | 146 |
| 6 | Um_nik | 143 |
| 7 | Errichto | 139 |
| 8 | adamant | 135 |
| 9 | BledDest | 134 |
| 10 | cry | 130 |
Problem : https://codeforces.me/contest/1538/problem/D
Solution Link : https://codeforces.me/contest/1538/submission/119077891
Can anyone explain why I am getting TLE on test 6 for this solution?
| Name |
|---|



I get TLE like you too. But after I changed using long long to int then I got AC.
This problem is so weird that you got AC when you use int but get TLE when you use long long
yeah I got AC too. But why long long is leading to TLE?
The time to process with long long is a little bit longer than that of int. So using int can speed up your program for a little bit and got AC in cases that your program execution time exceed the time limit with a very small amount of time.
Yeah, I remember one of the dp problems in CSES having the same problem, took me a long time to figure out what went wrong.
kshitijanand36 ..
I had the same problem. I fixed it by simply writing prime factorization (I counted all prime numbers from $$$2$$$ to $$$ \sqrt {10 ^ 9} $$$))
TL6: https://codeforces.me/contest/1538/submission/119027345
AC: https://codeforces.me/contest/1538/submission/119038949
i don't know why many people didn't get TLE with that solution. but as i know T*sqrt(1e9)*2 = 4e8 = 4seconds is TLE. at least, that's the reason for your TLE.
To be safe, you need to precalculate all prime numbers from 2 to sqrt(1e9) and only check thoses numbers.
Yes, I did the same and it worked