3 ms·
https://stackoverflow.com/a/54544012/1336678 https://stackoverflow.com/a/54544012/1336678 Common approach is to use square roots, this reduces the runtime. Rec
by Our_Benefactors 3y ago
https://stackoverflow.com/a/54544012/1336678 https://stackoverflow.com/a/54544012/1336678
Common approach is to use square roots, this reduces the runtime. Recommend checking out project euler if you like solving hard math-code-o(n)-puzzles.
- noduerme 3y agoI didn't want to cheat by looking on S.O. but thanks ;) Yes it makes sense (in the GPT code) that you'd only go up to i * i ... although looking at pythonic while: statements is just gross to me in this context, it would feel a lot more readable to say, e.g. in PHP: for ($i=2;$i<sqrt($n);) { $i+=($i==2 ? 1 : 2); //although the first one should just be outside the loop }