|
Project Information
|
This application will calculate the least common multiple for all integers between 2 and an integer specified. I thought up this algorithm for solving a problem I read about a long time ago; write a program that will find the least common multiple for all integers between 1 and 20, knowing that the least common multiple for all integers between 1 and 10 is 2520. http://thedailywtf.com/Articles/Out-of-All-the-Possible-Answers.aspx I basically reasoned that the least common multiple of any set of integers should be the product of their combined prime factors. For example, the least common multiple of 15 (prime factors 3 and 5) and 6 (2 and 3) should be the product of 2, 3, and 5. In cases where an integer had multi-occurring prime factors (for example, 9 has 3 occur twice), then the higher count would be kept. For example, the least common multiple of 15 (3, 5) and 18 (2, 3, 3) would be the product of 2, 3, 3, and 5. I've been itching to code this out since I first thought up the algorithm, which is probably proven by some mathematical theorem or other. This program currently lacks validation and error-handling. It maxes out at 42 because the LCM for 2 thru 43 or higher causes longs to roll over. I could probably refactor it to use Decimals, but...meh. It seems there are better solutions to this problem; http://stackoverflow.com/questions/185781/finding-the-lcm-of-a-range-of-numbers |