Questions tagged [lcm]

LCM(a, b) is the smallest positive integer that is divisible by both a and b.

Least common multiple (also called the lowest common multiple or smallest common multiple) of two integers a and b, usually denoted by LCM(a, b), is the smallest positive integer that is divisible by both a and b.

166 questions
0
votes
1 answer

long integers division error in python while finding least common multiple

Normally, program doesn't throw an error for small however when it comes to these numbers it returns wrong division result def leastCommonMultiple(n1, n2): a=n1 b=n2 while n2!=0: (n1, n2) = (n2, n1 % n2) print (n1) # greatest…
Semir Umut Kurt
  • 485
  • 5
  • 12
0
votes
1 answer

Smallest Common Multiple Divisible by

I'm working in JavaScript and I am solving for smallest common multiple, for two numbers, and the smallest common multiple has to be divisible by all numbers between the two numbers. Right now, my code is not working at all and nothing is being…
Daniel Semel
  • 175
  • 1
  • 1
  • 13
0
votes
3 answers

Calculate LCM of 2 numbers using templates

The program below computes a LCM of the 2 numbers, the expected output is 216 with a input of 54 and 24, but I get 57. Can someone help with the same, and let me know whats wrong with the code snippet below. /* *********** / *** LCM…
Sid
  • 81
  • 2
  • 6
0
votes
1 answer

Can't change the LCM credential of a DSC pull node

I'm trying to create my first DSC pull configuration. My node server can read its .mof files if I store them in a directory on the node server, but it can't access its configuration .mof from a configuration-repository-folder because it seems to not…
Samer
  • 3,848
  • 4
  • 25
  • 24
0
votes
1 answer

Perl - least common multiple

This code should do the LCM from N numbers. I tried to put prints wherever I can in order to see where is the mistake. and I think is in: if($vec[0] == $vec[$n-1]){ $resultado = $vec[0]; last; } But I can not make it work. Could you…
0
votes
1 answer

FInd Possible Permutations of Given Numbers whose Multiplication Gives the Required Number

Questions : A set of digits S separated by space is passed as input. A number N is also passed as the input. The program must find the two numbers N1, N2 from S so that N1*N2 = N and print them. Input Format: The set of digits in S separated by…
darthShadow
  • 1,027
  • 1
  • 12
  • 24
0
votes
0 answers

Given a number n, we have to find the sum of all pairs whose lcm (Least common multiple) is n itself ?

Example :- n = 4 Numbers -> {1,2,3,4} All possible pairs of these numbers. { {1,2},{1,3},{1,4},{2,3},{2,4},{3,4} } In these subsets subset {1,4} and {2,4} have lcm = n = 4; so we have to find sum of all numbers so our answer = 1+4+2+4 = 11.
Rakesh Meena
  • 59
  • 2
  • 8
0
votes
1 answer

speeding up nested lcm calculation

How can I speed up this calculation. I have tried some of way to reduce computation but nothing works. long long pairsFormLCM( int n ) { long long res = 0; for( int i = 1; i <= n; i++ ) for( int j = i; j <= n; j++ ) if(…
user3712917
  • 121
  • 1
  • 2
  • 13
0
votes
1 answer

While loop isn't working properly: GCD, LCM

This program for finding out GCD,LCM. I am facing problem when the program reach to while loop.My code is given below. public class GCDLCM { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int x =…
Atequer Rahman
  • 1,171
  • 10
  • 25
0
votes
0 answers

simplifing the code that would take out LCM

the following code is my original code i.e. i writed this code without copying others code or watching vedios to perform this function that would do the same. so what my code does is that, it would take out the LCM of any number: javascript …
anni
  • 290
  • 1
  • 3
  • 15
0
votes
1 answer

LCM calculation

I wrote code for the problem given in spoj to calculate LCM. I calculated the gcd of 2 numbers and I divided the multiplication of 2 numbers with gcd which gives the lcm of 2 numbers, but it is showing wrong answer. The problem is at…
Shashank
  • 87
  • 1
  • 2
  • 6
0
votes
0 answers

Implementing LCM with Fractions

My code is almost complete but I must figure out why my "reduceToLowestTerms() "doesn't get implemented through my code and make sure every time i enter a Fraction it does it. My code is a little long so I will be posting the link!…
0
votes
2 answers

smallest multiple javascript

I have to find the lcm of all the numbers 1 through and including 20, and I came up with this code. It, although is inefficient and also comes up with an answer that is 2 more than the correct answer. Could anyone tell me why? //variable used to…
UNEVERIS
  • 249
  • 1
  • 2
  • 8
0
votes
3 answers

Java method won't return answer in my LCM program

So what this program does is take two numbers as input using the Scanner class, and calculates the lowest common multiple of those two numbers. Everything seems to be working, except the lcm method won't return anything. I may have messed something…
ethanzh
  • 133
  • 2
  • 5
  • 19
0
votes
1 answer

How to avoid overflow error when finding LCM for series of large integers

I need to find least common divisor for a series of numbers (up to 100 000 numbers, each of them is in the range of [0, 2 000 000 000]) I am using the following algorithm lcm(a,b) = (a/gcd(a,b)) * b The standard method of finding lcm for for than 2…
Alin
  • 149
  • 1
  • 1
  • 7