Least Common Multiple: Explaining x=-2 and y=+3's LCM

  • Thread starter pyroknife
  • Start date
  • Tags
    Multiple
In summary, the programming code being discussed says that if one of two variables (x and y) is less than 0, then their least common multiple will be 0. This definition is not the usual one and may not be very useful. The code also includes a condition for handling negative values and returns 0 as an error signal. If negative values are valid, the operands can be wrapped in abs().
  • #1
pyroknife
613
3
I'm reading this programming code that basically says if 1 of 2 variables (x and y) is less than 0, then their least common multiple is 0.




If we have x=-2 and y=+3, then their least common multiple is 0.

I don't get it. I know what a least common multiple is, but this one isn't very intuitive to me.

Can someone explain?
 
Mathematics news on Phys.org
  • #2
That is not the usual definition. Usually lcm(-2,3)=6 and
lcm(a,b)=|ab|/gcd(a,b)
 
  • #3
pyroknife said:
I'm reading this programming code that basically says if 1 of 2 variables (x and y) is less than 0, then their least common multiple is 0.




If we have x=-2 and y=+3, then their least common multiple is 0.

I don't get it. I know what a least common multiple is, but this one isn't very intuitive to me.

Can someone explain?

Well, it's just a definition. It's not the usual definition and it's probably not a very useful one either. So there is no explanation other that the authors of the code implemented things like this.
 
  • #4
Part of the code written in C is:
if ( u < 0 || v < 0 )
return 0;

The overall code asks to find the lcm of u and v. If u or v is <0, then lcm of u and v is 0.
 
  • #5
Looks like the author considered it an error case and used a result of zero to signal an error condition back to the caller. This ought to be part of the declared interface. (But what does it return if an operand is 0?)
If negative values are valid in your case, just wrap the operands in abs().
 

1. What is the definition of Least Common Multiple (LCM)?

The Least Common Multiple (LCM) of two or more numbers is the smallest positive integer that is divisible by all of the given numbers.

2. How do you find the LCM of two numbers?

The LCM of two numbers can be found by listing out the multiples of each number and finding the smallest number that appears in both lists. Alternatively, you can use the prime factorization method, where you list out the prime factors of each number and then multiply the highest powers of each prime factor together.

3. Why is x=-2 and y=+3's LCM equal to 6?

The LCM of -2 and +3 is equal to 6 because 6 is the smallest positive integer that is divisible by both -2 and +3. This is because -2 and +3 are relatively prime, meaning they do not share any common prime factors. Therefore, their LCM is simply the product of the two numbers, which is 6.

4. Can the LCM of two numbers be negative?

No, the LCM of two numbers cannot be negative. LCM is always a positive integer because it is the smallest positive multiple that is divisible by both numbers.

5. Can the LCM of two numbers be equal to one of the numbers?

Yes, the LCM of two numbers can be equal to one of the numbers. This is because any number is a multiple of itself, and therefore, the LCM of a number and itself is equal to that number. For example, the LCM of 4 and 4 is 4.

Similar threads

Replies
1
Views
815
  • General Math
Replies
4
Views
3K
Replies
3
Views
1K
  • Calculus and Beyond Homework Help
Replies
24
Views
2K
  • General Math
Replies
11
Views
1K
Replies
11
Views
792
Replies
12
Views
2K
  • General Math
Replies
13
Views
1K
  • Programming and Computer Science
Replies
1
Views
735
Back
Top