Ad
  • Custom User Avatar

    Discarding multiples of 2 and 3 , we only have to look up for primes in 6i + 1 and 6i + 5, or starting an interation from 5 , 6i and 6i + 2 (i and i +2, step by 6). Meaning we would only look up numbers like 5, 7, 11, 13, 17, 19, 23, 25 (see, some of them would still not be prime).

    Overall this reduce the iteration to a third.

    So if we loop from 5 (having covered previous cases), we check x % i == 0 and x % i + 2 == 0 and i+=6 each loop, we save a lot of time for big numbers.

  • Custom User Avatar

    If some of you are interested, discarding multiples of 2 and 3 (i think), we only have to look up for primes in 6i + 1 and 6i + 5, or starting an interation from 5 , 6i and 6i + 2 (i and i +2, step by 6). Meaning we would only look up numbers like 5, 7, 11, 13, 17, 19, 23, 25 (see, some of them would still not be prime).

    Overall this reduce the iteration to a third.

  • Custom User Avatar

    If some of you are interested, discarding multiples of 2 and 3 (i think), we only have to look up for primes in 6i + 1 and 6i + 5, or starting an interation from 5 , 6i and 6i + 2 (i and i +2, step by 6). Meaning we would only look up numbers like 5, 7, 11, 13, 17, 19, 23, 25 (see, some of them would still not be prime).

    Overall this reduce the iteration to a third.

  • Custom User Avatar

    This comment is hidden because it contains spoiler information about the solution

  • Custom User Avatar

    you literally can just assign a value to a variable in each case and then use it in the mega block that you are repeating over and over

  • Custom User Avatar
  • Custom User Avatar

    If we initialize sum as 0, can't we skip first lenght check? 'for' wouldn't iterate through an empty array so sum would still be 0 and would be returned without any problem. Also .iter() is not necessary I think

  • Custom User Avatar

    More readable than other one-line options thank you very much ^^

  • Custom User Avatar

    As a rust beginner, are we suposed to code like that always?... 😨