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
2 answers

How does one update a field from outside the __init__() function with pyqt5

I am reading a sensor and want to display its output as a decimal number in a GUI using PyQt5. I have found a number of tutorials that point out the label.setText('myStr') function. This does not work for my setup, however, because I need to update…
Charles R
  • 49
  • 7
0
votes
3 answers

Least Common Multiple (LCM) - Python

This is not much about how do i do it and more about whats wrong with this method. I managed to solve this using other methods but i dont know why i cant with this one. what am i missing here? Example input: 4,6 Expected output: 12 Actual output:…
AleGPZ
  • 23
  • 4
0
votes
1 answer

LCM and then representing it in a matrix form

I have to find LCM and then represent them in a table. I found the LCM needed but I'm not sure how to format it on the table. |.... 20.... 21.... 22.... 23 .... ---+-------------------------------- 10 |20... 210...110... 230... 11…
0
votes
1 answer

How to find GCD and LCM using c#?

I have a problem finding GCD and LCM using C#. I considered to use a method where you break the two numbers down into two other numbers, for example breaking down 6 into 2 and 3, but I'm not sure how to do that using c#? Can someone please give me…
0
votes
2 answers

Function for GCD and LCM

I need a good function to be able to pass a list of numbers and get the GCD or LCM from it, normally it would say: def computeGCD(x, y): while(y): x, y = y, x % y return x >>> computeGCD(30, computeGCD(54, 72)) >>> 6 But I need a…
0
votes
0 answers

How to print only the unordered elements?

I am working on a code to print all the numbers which have their LCM as 240. Now this is pretty easy, write 2 for loops and you're done. I have provided the code below. What I want now is to remove duplicate pairs. For example, if I have already…
Ray Penber
  • 29
  • 8
0
votes
1 answer

L.C.M of two numbers in C

So, here is my code to calculate L.C.M (Least common multiple) without using G.C.D: int lcm(int x, int y){ int max = 0, min = 0, ans = 0; if(y >= x){ max = y; min = x; if(y % x == 0) return y; }else { …
Abhijit
  • 468
  • 8
  • 22
0
votes
1 answer

Least Common Multiple of 2 numbers by prime factors of number

In this code, I am trying to get prime factors for the prime method to find LCM. then I am trying to save it by counter but I am not able to divide both key and values for the proper method. I'm stuck at counter, please can anyone help me? from…
Rutvik
  • 11
  • 1
0
votes
3 answers

How to loop over modulus?

newbie here. I've been trying to find the least common multiple of the numbers 1 thru 10. My code so far def smallest_multiple(): a = 0 while True: a += 1 if a%1 == 0 and a%2 == 0 and a%3 == 0 and a%4 == 0 and a%5 == 0 and a%6 == 0 and a%7…
Jose Gallo
  • 93
  • 2
  • 6
0
votes
1 answer

LCM of n-1 elements in SML

I have the following functions to calculate the LCM of all elements from a list. Are there any hints for calculating every LCM of each (n-1) subsets and store them in a list instead? fun modulo (_,0) = 0 | modulo (0,_) = 0 | modulo (x,y) = if y…
0
votes
5 answers

LCM of two numbers

I am getting wrong result for my LCM program. Ifirst find gcd of the numbers and then divide the product with gcd. int gcd(int x, int y) { while(y != 0) { int save = y; y = x % y; x = save; } return y; } int lcm(int x, int…
user642371
  • 11
  • 1
  • 4
0
votes
1 answer

PROLOG - LCM of couples in list

I want to find the Least Common Multiple (LCM) of couples from a list. But in the following way: For example if I have this list: L1 = [1,2,3,4,5]. I want to produce this list: L2 = [1,2,6,12,60]. I use the first element of L1 as first element of…
guruste
  • 5
  • 1
  • 1
  • 4
0
votes
4 answers

How to dereference multiple void pointers in structs into 1 piece of memory?

I am working on a project where I need to send over a certain IPC stack, (in my case, LCM), and the thing is I need to provide the IPC a variable length struct. I have struct pack1 {int value1; int value2;}; struct pack2 {void *data; int…
Sergio Campamá
  • 746
  • 1
  • 7
  • 14
0
votes
1 answer

How should I store a value in list_=[ ] while calculating the LCM between two numbers?

How should I store a value in list_=[ ] while calculating the LCM between two numbers? I need to store every factor for both the numbers. My code is: def lcm(x, y): if x > y: greater = x else: greater = y lcms =[] …
0
votes
2 answers

Lowest fraction Value In Oracle

I am trying to create a function to return lowest fraction value. the sample code is here : create or replace function fraction_sh(x number) return varchar2 is fra1 number; pwr number; intprt number; v4 number; numer number; …
Vikrant Jain
  • 135
  • 1
  • 11