Problem : https://mirror.codeforces.com/contest/1538/problem/D
Solution Link : https://mirror.codeforces.com/contest/1538/submission/119077891
Can anyone explain why I am getting TLE on test 6 for this solution?
Problem : https://mirror.codeforces.com/contest/1538/problem/D
Solution Link : https://mirror.codeforces.com/contest/1538/submission/119077891
Can anyone explain why I am getting TLE on test 6 for this solution?
| # | User | Rating |
|---|---|---|
| 1 | Benq | 3792 |
| 2 | VivaciousAubergine | 3647 |
| 3 | Kevin114514 | 3603 |
| 4 | jiangly | 3583 |
| 5 | turmax | 3559 |
| 6 | tourist | 3541 |
| 7 | strapple | 3515 |
| 8 | ksun48 | 3461 |
| 9 | dXqwq | 3436 |
| 10 | Otomachi_Una | 3413 |
| # | User | Contrib. |
|---|---|---|
| 1 | Qingyu | 157 |
| 2 | adamant | 153 |
| 3 | Um_nik | 147 |
| 3 | Proof_by_QED | 147 |
| 5 | Dominater069 | 145 |
| 6 | errorgorn | 142 |
| 7 | cry | 139 |
| 8 | YuukiS | 135 |
| 9 | TheScrasse | 134 |
| 10 | chromate00 | 133 |
| 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://mirror.codeforces.com/contest/1538/submission/119027345
AC: https://mirror.codeforces.com/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