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
1
vote
4 answers

Calculate LCM of N numbers modulo 1000000007

I was solving following problem on LCM : Calculate LCM of N numbers modulo 1000000007 My approach : typedef unsigned long long ull; const ull mod=1000000007; ull A[10009]; /*Euclidean GCD*/ ull gcd(ull a,ull b) { while( b != 0) { ull…
Ritesh Kumar Gupta
  • 5,055
  • 7
  • 45
  • 71
1
vote
2 answers

Working Example to find the LCM of more than 2 Numbers

Android 2.3.3 I have written a program for calculating the LCM for more than 2 numbers, and it worked for me. I thought of sharing it, so that it might come in handy for those who are looking for it. This may not be the best solution, but, i did it…
Vamsi Challa
  • 11,038
  • 31
  • 99
  • 149
1
vote
10 answers

Project Euler #5(Smallest positive number divisible by all numbers from 1 to 20): Ways to Optimize? ~Java

Problem 5: 2520 is the smallest number that can be divided by each of the numbers from 1 to 10 without any remainder. What is the smallest positive number that is evenly divisible by all of the numbers from 1 to 20? I have solved the problem 5 of…
Akhil Jain
  • 13,872
  • 15
  • 57
  • 93
1
vote
1 answer

how would i put a whole bunch of float numbers into a list and then find the lowest common multiple of all the numbers?

how would i put a whole bunch of float numbers into a list and then find the lowest common multiple of all the numbers? My problem is that i have a text file with info on solar systems and i have isolated the value for the period of revolution for…
1
vote
2 answers

C++ program to compute lcm of numbers between 1 to 20 (project euler )

as the title explains this is a program to find lcm of numbers between 1 to 20. i found an algorithm to do this, here's the link http://www.cut-the-knot.org/Curriculum/Arithmetic/LCM.shtml there is a java applet on the webpage that might explain the…
rudha
  • 11
  • 3
0
votes
1 answer

Lightweight Communications Marshalling - lcm-spy is not displaying messaged published over lcm

I have lcm installed and running on a Ubuntu 18 computer and I can see my lcm messages displayed in the lcm-spy GUI. I recently installed lcm on a Ubuntu 22 computer using the commands: sudo apt-get install liblcm-dev and sudo apt install…
dk523
  • 11
  • 2
0
votes
1 answer

how can I FIND hcf and lcm of number with time complexity O(log n ) by using vectors

In this program,we need to find hcf and lcm of a number and must use vector for it and time complexity should be O(log n) and using c++. class Solution { public: vector lcmAndGcd(long long A , long long B) { …
0
votes
0 answers

How to pass a range of many numbers as arguments to math.lcm()?

According to this, the math.lcm() function: Return the least common multiple of the specified integer arguments. If all arguments are nonzero, then the returned value is the smallest positive integer which is a multiple of all arguments. If I want…
plpm
  • 539
  • 3
  • 12
0
votes
0 answers

Finding if the lcm of a list is in the set 3^d

I need to find a better way to raise the 'tes' variable in python till I can get the print out to terminate. (Running rather slow at 700) I propose the need for a better way of defining the 'shifts' list, and reducing redundancies since the problem…
Numoru
  • 3
  • 6
0
votes
0 answers

How to find this GCD and LCM

Im trying to find this GCD and LCM in C GCD example : Input 1 : 20 Input 2 : 15 Num1 : 20 = 2 x 2 x 5 Num2 : 15 = 3 x 5 GCD = 5 and LCM example : Input 1 : 20 Input 2 : 15 15 : 15, 30, 45, 60, 75, 90, 105, 120, 135, ... 20 : 20, 40, 60, 80, 100,…
sl0th
  • 1
0
votes
1 answer

Why does the output always show 0 as LCM?

https://github.com/mehedihasrifat Please correct my mistake** How can I solve this issue? Did I do something wrong here?** I have been trying to debug this code but ultimately I can't. Please help me, I'm totally new to this platform. This…
0
votes
1 answer

Issue in calculating LCM of two -ve numbers or if either one is negative in C lang

The code is running perfectly for finding LCM of 2 and 3 , LCM of 0 and 2 BUT not able to execute for (-2 and 3) or (-2 and -3). I have written code for this type. Check else if block that's the problem. I expect LCM of -2 and -3 to get printed as…
0
votes
3 answers

How to find lcm of two numbers efficiently (With out using any module like `np.lcm`)?

I get this from the internet but it takes about 1 minute for the large numbers. import time def lcm(x,y): if x>y: greater=x else: greater=y while(True): if((greater%x==0) and (greater%y==0)): …
codester_09
  • 5,622
  • 2
  • 5
  • 27
0
votes
0 answers

Agrgumental Error in finding LCM using Python what am i doing wrong

Hi I am experiencing a issue with writing a code to find lcm of 2 numbers the code is as follows def compute_lcm(x, y): if x > y: greater = x else: greater = y while(True): if((greater % x == 0) and (greater % y ==…
0
votes
1 answer

Can I solve this problem with Dynamic Programming?

How I find among all pairs a and b with a "least common multiple" LCM(a,b) = 498960 and a "greatest common divisor" GDM(a, b) = 12 a pair with minimum sum a + b? I solved this with O(n^2) time: public class FindLcmAndGcdClass { private int…