4 ms·
I think they're suggesting simply doing +2 +1 is not a good idea since ~half of all numbers are effectively non-prime simply by being even numbers. You can do
by thewataccount 3y ago
I think they're suggesting simply doing +2
+1 is not a good idea since ~half of all numbers are effectively non-prime simply by being even numbers.
You can double the speed by using +2 without using any fancy tricks, just changing a single character.
- nojs 3y agoWell it doesn’t double the speed, since anything with a factor of 2 undergoes only one loop iteration inside is_prime. It basically just saves a function call