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

LCM of list PROLOG

How to get the LCM of a list in Prolog? Lets say the list is: [1,2,3,4,5] and the LCM will be 60. I have the following code fo the GCD and the LCM that work for 2 numbers but dont know how to apply to lists. gcd(X, 0, X) :- !. gcd(X, Y, Z) :- H…
0
votes
2 answers

Finding GCD and LCM giving correct output for some test cases but my submission shows wrong answer

My c++ code of finding gcd and lcm is giving correct output for some test cases but my submission shows wrong answer. int T; cin>>T; int x,y,a,b; while(T--) { cin>>x>>y; a=(x>y)?x:y; // a will be the greater number b=(y>x)?x:y; // b…
Shrusky
  • 3
  • 2
0
votes
1 answer

Could NOT find GLib2_glib (missing: GLIB2_GLIB_LIBRARY GLIB2_GLIB_INCLUDE_DIR GLIB2_GLIBCONFIG_INCLUDE_DIR)

When I trying to install LCM in my Ubuntu, using commands $ mkdir build $ cd build $ cmake .. $ make $ sudo make install and when comes to $cmake .. it returns : -- Could NOT find GLib2_glib (missing: GLIB2_GLIB_LIBRARY GLIB2_GLIB_INCLUDE_DIR…
0
votes
1 answer

C Programming: to find hcf and lcm of three integer

I am new in this programming field,so i am facing a lots of problem while writing code.My question is to find hcf and lcm of 3 integers given by the user....I got stucked at half, so please help me to complete this code, I know how to calculate hcf…
Eva Maria
  • 1
  • 1
0
votes
1 answer

How can I get the LCM of 2 numbers without GCD?

I'm trying to make a Fraction Calculator in VB.NET, but I'm stuck with the LCM part. I found some code on the internet: Public Shared Function GCD(a As Integer, b As Integer) As Integer If a = 0 Then Return b End If …
TIPDYT
  • 3
  • 1
0
votes
3 answers

My function for finding LCM does not work. Is there a problem with the while loop?

My function for finding LCM does not work. Is there a problem with the while loop? x = int(input("Enter the first number")) y = int(input("Enter the second number")) def calculate_LCM(x,y): if (x>y): max=x else: max=y …
Lotus
  • 11
  • 4
0
votes
0 answers

sympy: compute lcm() of polynomials without expanding the result

When I compute the LCM of multiple polynomials, the result seems to be always expanded: >>> from sympy import lcm >>> from sympy.abc import x,y,z >>> lcm([x+y,y+z,z+x]) x**2*y + x**2*z + x*y**2 + 2*x*y*z + x*z**2 + y**2*z + y*z**2 I'd rather get…
cxxl
  • 4,939
  • 3
  • 31
  • 52
0
votes
0 answers

Could my solution to the 5th Euler Project(Java) problem(LCM of 1 through 20) be optimized?

I have been going through the Euler project problems one by one every day and asking whatever questions I have on this website. The problem description is commented out in the code. This time around, I don't have any particular problems with my…
Vasila_M
  • 53
  • 6
0
votes
1 answer

LCM of 2 strings

I have to find the LCM of 2 strings given that a multiplication operation exists between a number and a string which dictates that if x is a number and s is a string, then s*x is equal to the string s taken x times. the strings given are "baba" and…
Mohit Singh
  • 143
  • 11
0
votes
2 answers

Trying to find LCM(least common multiple) with Python

My code is this: num1 = int(input(": ")) num2 = int(input(": ")) list1 = [] x, z, y = 0, 0, 0 while x < 100: z += num1 y += num2 list1.append(z) list1.append(y) x += 1 for i in list1: if list1.count(i) > 1: print(i) …
Krupskaya
  • 1
  • 1
0
votes
0 answers

To find the smallest number divisible by first n numbers

When I try to run the following code, I am getting a warning as floating point exception(core dumped). Can someone please tell me what mistake I am doing here? The program is to find the smallest number divisible by first n numbers. Ex : if input=4…
Raksha
  • 13
  • 4
0
votes
1 answer

Finding the lowest common multiple of a list of integers without using gcd in python

Input -> a=[16,21, 56, 40] **Code I wrote** def find_primes(a): num_factors=[] for num in a: # print('1',num) list_of_factors=[] i=2 while num>1: #print('2',num) if num%i==0: …
Ann
  • 1
  • 2
0
votes
1 answer

To find lcm without gcd algorithm-regarding

I tried it,but eventually I wrote a program for more than 30 lines.So, I looked for solution on geeksforgeeks, def findLCM(a, b): lar = max(a, b) small = min(a, b) i = lar while(1) : if (i % small == 0): …
0
votes
1 answer

Finding the Least Common Multiple(LCM) of two integer in C

I am trying to use the following code to find the LCM of two integers in C. I have no idea why the code will show me the maximum number of the two integers instead of the LCM of them. Have I do something wrong? #include int main(){ int…
itztaylorau
  • 5
  • 1
  • 3
0
votes
2 answers

How do I create a function for finding the Least Common Multiple of a vector of integers using Greatest Common Factor in R?

Suppose I have a function gcf(x,y) that returns the greatest common factor of x and y. So, for example, gcf(75,85) = 5 Now, I'm trying to create a function lcm(v) that takes a vector of integers and returns the least common multiple. I know…
Jayden Rice
  • 301
  • 1
  • 14