How to find the number that's evenly divisible by a set of numbers from 1 to n?

In summary, the conversation discusses the problem of finding the smallest number (x) that is evenly divisible by a set of numbers from 1 to n. The solution is to find the lowest common multiple (LCM) of the set, which can be calculated using the formula LCM(a,b) = |a*b|/GCD(a,b) where a and b are two numbers. The GCD can be found using the Euclidean algorithm. Alternatively, a brute force approach can be used, but it is important to consider the number 2 when calculating the LCM.
  • #1
newb
10
0
How can you go about finding the smallest number (x) that is evenly divisible by a set of numbers from 1 to n?

For example:

If n = 3, x=6
n = 4, x=12
n=5, x=60
n=6, x=60


This is easy to do when n is a small number, however how would one go about finding the answer if n=20 for example?

I have written a program that tries to brute force the answer, but I'm almost certain there's a much more elegant way to do it. Any advice?
 
Mathematics news on Phys.org
  • #2
Here's the program I wrote by the way, incase anyone is interested:
Code:
class Problem5 {
 static int[] theArray;
static int multiplyer = 11 ; 
 static boolean test= false;
static int current;


 //Makes array
 void maker (int number){
   for(int i=number; i>0; i--){
     theArray[i-1]=i;
     
   }
  }   
   
  public static void main (String[] args){
 
   Problem5 instance1 = new Problem5();
   theArray = new int[multiplyer];
   instance1.maker(multiplyer);
   current = theArray[theArray.length-1];
   System.out.println (current);
   
   while (test == false){
     for(int i = theArray.length; i>0; i--){
     if (current % theArray[i-1]>0){
       current = current + theArray[multiplyer -1];
       i=0;
       test = false;
     } else{
       System.out.println(current+" is divisible by "+ theArray[i-1]);
       test = true;
     }
    }  
   }
     
  }
     
}
 
Last edited by a moderator:
  • #3
Phrased another way, your problem is to find the lowest common multiple (LCM) of a set of numbers from 1,...,n . Luckily, there is an easy formula to get the LCM for two numbers a and b from the greatest common divisor (GCD): LCM(a,b) = |a*b|/GCD(a,b) . I say luckily because finding the GCD is easy - just use the Euclidean algorithm. There's probably a snazzy way to deal with this for more than two numbers but you could adopt it by finding LCM(a,b), then LCM(LCM(a,b),c), etc. Check out http://en.wikipedia.org/wiki/Least_common_multiple

If you stick with a brute force approach, remember that apart from {1}, each set contains 2. Think about what this means for the LCM...
 

1. How can I find the number that is evenly divisible by a set of numbers from 1 to n?

To find the number that is evenly divisible by a set of numbers from 1 to n, you can use the Least Common Multiple (LCM) method. This involves finding the smallest number that is a multiple of all the given numbers. You can also use prime factorization or the Euclidean algorithm to find the LCM.

2. Is there a formula for finding the number that is evenly divisible by a set of numbers from 1 to n?

There is no one formula that can be used for all cases, but there are various methods and algorithms that can be used to find the number that is evenly divisible by a set of numbers from 1 to n. These methods involve finding the LCM or using prime factorization, and they can be applied depending on the specific numbers in the set.

3. Can I use a calculator to find the number that is evenly divisible by a set of numbers from 1 to n?

Yes, you can use a calculator to find the number that is evenly divisible by a set of numbers from 1 to n. Most scientific calculators have a function for finding the LCM or prime factorization, which can be used to determine the number that is divisible by a given set of numbers.

4. What happens if there is no number that is evenly divisible by a set of numbers from 1 to n?

If there is no number that is evenly divisible by a set of numbers from 1 to n, it means that the numbers in the set have no common multiple. This can happen when the numbers are prime or have no common factors. In this case, the LCM would be equal to the product of all the numbers in the set.

5. Can the number that is evenly divisible by a set of numbers from 1 to n be negative?

Yes, the number that is evenly divisible by a set of numbers from 1 to n can be negative. This can happen when the numbers in the set have a common factor of -1, or when the LCM is a negative number. However, it is more common to express the number as a positive integer.

Similar threads

Replies
2
Views
690
Replies
5
Views
2K
Replies
4
Views
407
  • General Math
Replies
2
Views
989
Replies
55
Views
3K
Replies
7
Views
1K
Replies
6
Views
1K
  • Set Theory, Logic, Probability, Statistics
Replies
13
Views
2K
Back
Top