Ad
  • Default User Avatar

    The for loop starts from the first prime number (2) and if n would be divisible by non-prime i, it also means that it is divisible by i prime factors. So n would be reduced (n /= i) in earlier loop steps, n % i == 0 can be true only for prime i because of it.