Because cc
gets quite large, there is a small advantage to altering your short cut test to avoid a multiplication inside the loop on a
(cost for this is a single divide outside). There are a lot of cutoffs on rad[a]rad[a]
is too large. (and there might be even more if you apply this heuristic on b
instead).
for c in range(limit):
for a in range(1, c // 2):
if rad[a] * rad[c] >= c:
continue
Can be made marginally faster by changing it to the equivalent form (we know that c, rad[c] > 0
)
for c in range(limit):
alim = c // rad[c];
for a in range(1, (c + 1) // 2):
if rad[a] >= alim:
continue