What is the smallest positive number that is evenly divisible by all of the numbers from 1 to 20?
Solution:
First we try to solve the problem using a brute force methode.
First we try to solve the problem using a brute force methode.
Problem05 = 232792560 elapsed time: 8548 ms. Test Passed.
Performance improvement:
1) Because the number must be divisible by 20 we can optimize the outer for loop with n+=20.
2) If a number is divisible by 18 it is also divisible by 9 so desend 2nd for loop until 10.

Problem05 = 232792560 elapsed time: 99 ms. Test Passed.
Performance improvement:
1) Because the number must be divisible by 20 we can optimize the outer for loop with n+=20.
2) If a number is divisible by 18 it is also divisible by 9 so desend 2nd for loop until 10.

Problem05 = 232792560 elapsed time: 99 ms. Test Passed.
Geen opmerkingen:
Een reactie posten