I am trying to calculate the sum of the smallest prime factors of n, where 2 < n < 10**12, and get the remainder of this sum when divided by 10**9:require 'prime'puts Started at #{Time.now}.num = 10**12sum = 0(2..num).each { |n| sum += n.prime_division[0][0] }sum = sum % 10**9p sumputs Finished at #{Time.now}.Understanding that the smallest prime factor of any even number is 2, and the smallest prime factor of any prime number is itself, I made the following function:def findSmallestPrimeFactor(number)  return 2 if number.even?  return number if Prime.prime? number  return number.prime_division[0][0]endHowever I feel this would have no effect on the program's run time as #prime_division works well enough on any number.Is there any way to shorten the runtime of this program? I have been told that efficient implementation will allow the program to finish in under 1 minute, however I can't see how I can do this without iterating over every number between 2 and one trillion (10**12), which will take several days regardless.
Calculating sum of smallest prime factors for 2 < n < 10**12
ruby;time limit exceeded