So, first programming course, first nongraded assignment: In C++, for the range of numbers from 1 to 1 billion, find the sum of the numbers that are divisible (without remainder) by all 1 through 99. How do I go about this? How do I even find the lowest number divisible by 1:99?
edit: this isn't hw to be turned in, just something to think about. I would try some type of vectorizing in matlab, but this is my first day trying c++ so I really have no idea, I just learned how to initialize a variable.
// In pseudocode a very basic algorithm:
main
for i: 1 to 1000000000
if (TestValue(i))
Output(i)
TestValue(i)
for j: 1 to 99
if j does not divide i evenly
return false
return true
Of course, this won't be very performant. You might notice that if a number is evenly divisible by all numbers between 1 and 99, then it must be divisible by the set of prime factors in 1..99. For instance, in 1..19 the prime factors are: 2, 2, 2, 2, 3, 3, 5, 7, 11, 13, 17, 19. If something is evenly divisible by all numbers 1..19 then it must be evenly divisible by 2*2*2*2*3*3*5*7*11*13*17*19 = 232792560. To find all the numbers between 1 and 1000000000 that are evenly divisible by 1..19, I would find all the numbers between 1 and 1000000000 that are evenly divisible by 232792560 instead.