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

python code showing wrong output when computing least common multiple for large integers

I implemented an lcm problem using the following algorithm in python. My code is given below : # Uses python3 import sys def gcd_efficient(a, b): #current_gcd = 1 #for d in range(2, min(a, b) + 1): # if a % d == 0 and b % d == 0: …
0
votes
0 answers

How to find GCD and LCM from set of number using ArrayList

I have a problem how to find GCD and LCM using ArrayList. Now I have implemented Euklides algorithm using primitive type. Below are my model and view packages. Please give me advice how change method in the model? Model: package Model; import…
0
votes
0 answers

Python: Creating my own LCM function

I'm completely new to Stack Overflow, and a complete newbie when it comes to coding. However, I'm working hard and trying to get creative with my self learning. Right now, I'm trying to code an LCM function which takes multiple numbers as input, and…
0
votes
2 answers

how can I quickly get answer of LCM by python

def getLCM(a, b): c, d = max(a, b), min(a, b) while c != d: temp = c - d c, d = max(temp, d), min(temp, d) return a * b // c def nlcm(num): temp = 1 while len(num) != 0: temp = getLCM(temp, num[-1]) …
전현근
  • 21
  • 2
0
votes
3 answers

Getting the prime factors of two arrays

Hello guys I am trying to create an LCM function that takes in two numbers. The findCommonMultiple() function in this piece of code basically returns an array for the prime factors for that number. What I'm trying to do in this function is to check…
user7452246
0
votes
1 answer

LCM application : no output

I'm solving this problem There are two kangaroos on a number line ready to jump in the positive direction (i.e, toward positive infinity). The first kangaroo starts at location x1 and moves at a rate of v1 meters per jump. The second kangaroo…
Karan
  • 11
  • 1
  • 5
0
votes
1 answer

least common multiple: What is wrong with my code?

function lcm(arr) { arr = arr.sort(function(a, b) { return a - b; }); var j = 1; var num = arr[0]; for (i = 1; i < arr.length; i++) { while (num % arr[i] !== 0) { j = j + 1; num = j * arr[0]; } …
Dr. Younes Henni
  • 1,613
  • 1
  • 18
  • 22
0
votes
1 answer

Cross compiled software produce a wrong output

I have cross compiled a software for an HummingBoard-Pro (arm processor). The software just receives some data using the lcm protocol. If I use the cross compiled software, the data received by the application are invalid, while if I use on-board…
Franconet
  • 41
  • 1
  • 10
0
votes
0 answers

Least common multiple and gcd in assembly

I'm trying to write a program, which calculates lcm and gcd of two unsigned longs in assembly x86-64, but I get some floating point error, when I'm launching my program. The error is in polish, but I can translate it into "Floating point operations…
user5987748
0
votes
0 answers

How can I calculate this special "lcm"?

I have achieved calculating normal lcm for any number of int. But what I want is more like a "special" lcm - don't know how to discribe this better, I'd appreciate someone could improve the question. For example: I have {15, 21} The "normal" lcm…
RadarNyan
  • 306
  • 1
  • 2
  • 12
0
votes
2 answers

From 1 to N how many pairs have LCM = N?

Suppose N = 8. There are 4 pairs (1,8),(2,8),(4,8),(8,8) whose LCM is 8. If N = 6. Then there are 5 pairs (1,6),(2,6),(2,3),(3,6),(6,6) whose LCM is 6. Now I want to know how to find the number of pairs quickly?
0
votes
1 answer

JavaScript integer overflow workaround

I need to perform arithmetical operations with large numbers in JS, in this particular case it is: (1827116622 / 6) * 251772294 The expected result is 76669557221078478 but I am getting 76669557221078460 because of integer overflow. The environment…
0
votes
0 answers

Powershell DSC Custom Resource with PSCredential array Property throws Error MI RESULT 13

Background: When creating a Custom DSC Resource using the DSC resource designer you can specify a New-xDscResourceProperty with a type of PSCredential[] (PSCredential array). Problem: When I create an extemely simple custom resource that uses…
Randy Rakestraw
  • 331
  • 1
  • 10
0
votes
2 answers

LCM of large numbers in python

I'm using the formula "product of two number is equal to the product of their GCD and LCM". Here's my code : # Uses python3 import sys def hcf(x, y): while(y): x, y = y, x % y return x a,b =…
Parth Jeet
  • 129
  • 2
  • 15
0
votes
3 answers

Overflow of answer for larger values

i am trying to find the LCM of a number using the following formula. Lcm = Gcd/(a*b). This is working fine for small number, however for larger numbers it overflows, like the one shown in the code. I tried using long long as the variable type but…
Muneeb Rehman
  • 135
  • 2
  • 10