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 N+1 consecutive numbers

How we can write code to find solution of following: (N+1)*X =LCM( 1,2,3,4,5,6,......,N,N+1) use mod when it gets greater then (10^9 +7) . USE MOD=(10^9 +7). I had written following code fragement but its not working: ll dp[100005]; ll gcd (ll…
0
votes
1 answer

Wrong Answer in interview street challenge

First of all a small clarification.I did got AC in this problem,but my better approach (which is mathematically equivalent,I assume to my AC solution) is getting a WA verdict There is a problem in interviewstreet which goes like this: There is one…
bashrc
  • 4,725
  • 1
  • 22
  • 49
0
votes
1 answer

A Java lib that has a utility for finding the least common multiple of a set of integers

I would like to find the least common multiple of a set of integers. Does a numerical Java library that does this exist? Please provide a link to it.
hidarikani
  • 1,121
  • 1
  • 11
  • 25
-1
votes
5 answers

How to find Least Common Multiple (LCM) for two numbers

I have used Euclid's method to find the L.C.M for two numbers. l.c.m=a*b/(gcd(a,b)) How can I do this without using this algorithm? I have an idea of first getting all factors of these two numbers and storing them in array. Then take 1 element from…
Sharpzain120
  • 365
  • 3
  • 9
  • 18
-1
votes
1 answer

My code is not working. Write a C program to find GCD and LCM of ‘n’ numbers, with n being the input from user

I thought of declaring the variables first, and then finding the gcd and lcm. But when I tried to run, my code is not working. And the VS code is not even showing the errors. I am posting my code here: #include int gcd(int a, int b) { …
Utk
  • 11
  • 1
-1
votes
1 answer

why can't this code be used to find the lcm of two numbers?

This is the code I wrote. Please tell me the mistakes and knowledge gap I may have #include int main() { int i,n,c=1; printf("enter the number 1:"); scanf("%d",&i); printf("enter the second number:"); scanf("%d",&n); …
-1
votes
1 answer

Finding Lowest Common Multiple using numpy (for more than two inputs)

So I would like to find the lowest common multiple of 4 or more numbers in python. Now I understand that in numpy, you can just use np.lcm but the function is only restricted to two inputs. import numpy as np result = np.lcm(12, 8) # calculating the…
-1
votes
3 answers

Javascript for loop giving infinite loop error while calculating LCM

The problem I'm trying to solve is to calculate least common multiple of a given range of numbers. The numbers supplied in the array can be in any order, but the attay will only have two numbers. My code works for pairs [1,5] , [1,10],[1,12], but…
rk_manne
  • 13
  • 4
-1
votes
2 answers

Java code for calculating GCD and LCM of two numbers is working fine but not being accepted on one of the online platforms

below is my code for calculating gcd and lcm of two numbers. When i try with different test cases it works fine. But when i try to submit it on online platform it says wrong package javapractice; import java.util.*; public class chef_gcdlcm { …
RAP
  • 21
  • 6
-1
votes
1 answer

Finding LCM of two nos in C

I have created a code for finding LCM of two nos. I think that the code is correct but I have an undesired output. What ks the problem in this code? #include #include main() { int i, j, a, b, lcm; printf("Enter two nos :…
-1
votes
2 answers

Belt Collision Time Calculation

Mr. Dis and Mr. Aster are mechanical engineers at Fiasco Iron Works. They were assigned to design roadways for automated trolleys to carry the iron ores across the smelting plants. They were supposed to make two circular roadways for the…
user9291964
-1
votes
2 answers

LCM and GCD 3 Number - Python

This is my code so far. from math import gcd #3 digit lcm calculation h=input("(1) 2 Digit LCM Or \n(2) 3 Digit LCM\n :") if h == "2": while True: def lcm(x, y, z): a = gcd(x, y, z) num = x num2 = y *…
Bilbo
  • 56
  • 1
  • 9
-1
votes
2 answers

Recursive function for LCM in C++ using multiple numbers

Please can someone help me with the recursive function to find the LCM of an array of ints. The function call will be: int LCM(int * arr, int length){} Please can someone help me.
-1
votes
1 answer

Find LCM of two numbers

The program should first ask that I enter how many times it should ask me for two numbers. After I give two numbers it should find the LCM of them and do the operation as many times as I entered in the beginning. It opens and waits for me to give…
gabi 13
  • 17
  • 2
-2
votes
1 answer

How do I make LCM works with floating numbers?

Newbie to python... Currently I'm writing a code for physics calculator, mirror especially, the formula of the mirror is 1/s + 1/s' = 1/f. Example, I want to input the number to the s' is 3 and the f is 1.2 1/s + 1/3 = 1/1.2 ...and now I wanted…