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
-2
votes
1 answer

Updated: Finding the least common multiple of a list of numbers in python

Hi I have updated this with my code: Input -> a=[16,21, 56, 40] 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…
Ann
  • 1
  • 2
-2
votes
2 answers

How is the gcd function finding the lcm?

How is the gcd function below working I do not understand what the ger varible does. Also what is the lcm varible doing I find this function hard to understand I am not good at math. long lcm,hcf = 0; long i=1; // This sets ger to max(a,b)…
Run Usb
  • 1
  • 1
-2
votes
2 answers

How to reach a common number by adding a number k, to an array of numbers arr[]?

I am stuck with an algorithm problem since days. If we have an array of numbers, lets say, arr[2,4,9] and a var k, lets say k=7. Is there a common number possible which can be reached by adding k to each of the elements inside the arr[]…
-2
votes
2 answers

LCM program in C++

#include using std::cout; using std::cin; int main() { int num1 = 0; int num2 = 0; cout << "Please enter two numbers (remember to put a space between them):\n"; cin >> num1 >> num2; const int num_limit = num1 *…
Njgardner90
  • 61
  • 1
  • 7
-2
votes
1 answer

finding the LCM using python

def multiple(a, b): """so I'm trying to return the smallest number n that is a multiple of both a and b. for example: multiple(3, 4) 12 multiple(14, 21) 42 """ def gcd (a,b): if a < b : a , b = b,a …
urviguglani
  • 127
  • 1
  • 1
  • 11
-2
votes
4 answers

python program to find hcf and lcm

i wrote the following progran in python to find out hcf and lcm of two numbers a and b. x is the greater of the two numbers and y is smaller, both of which i intend to find in upper part of program. they will be used later for finding hcf and…
Tarun Khare
  • 1,447
  • 6
  • 25
  • 43
-2
votes
1 answer

LCM for combinations

Two integers n and k, both ranging in 100000 is given. How do we calculate the LCM for n*n-1C0(multiplication of n and (n-1 choose 0)), n*n-1C1(multiplication of n and (n-1 choose 1)), n*n-1C2(multiplication of n and (n-1 choose 2)), ..........,…
MetaD
  • 87
  • 1
  • 8
-2
votes
1 answer

Project Euler #5 | can't understand solution

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(divisible with no remainder) by all of the numbers from 1 to N? Input Format…
Aneesh Dandime
  • 123
  • 1
  • 11
-2
votes
1 answer

calculating the gcd and lcm of 5 numbers

how can i calculate the GCD and LCM of 5 numbers using a loop that i should create?? this is what i started doing but i think i started in wrong way from the beginning can anyone help public static void main(String[] args) { // TODO…
-3
votes
1 answer

Pine script the least common multiple (LCM)

I'm trying to find pine script lcm. Masters, can you please help? I could not be successful. It should be very simple for you. Please help me //@version=5 indicator(title='1', overlay=false, precision=2, timeframe='') x = input(15) y =…
-3
votes
2 answers

What is wrong with the following c code? the gcd stops working after i enter into the loop

#include int gcd(int a, int b); int lcm(int x ,int y); int main() { int num1, num2, k, hcf,max,n; scanf("%d",n); for (k=0;k
Yusuf Jk
  • 1
  • 1
  • 4
-4
votes
3 answers

How do I find the least b from lcm(a,b) = c?

I know a and c. How can I find the least b if lcm(a,b) = c?
-4
votes
1 answer

lcm of all numbers in an array in c++

I came across this piece of code to compute least common factor of all numbers in an array but could not understand the algorithm used. What is the use of __builtin_popcount here which is used to count the number of set bits? pair
kolaveri
  • 59
  • 1
  • 2
  • 15
-4
votes
2 answers

How to discard scanf errors and identifying highest prime number from 4 input integers using multi threading

I am solving a question to calculate LCM and highest prime number from a set of 4 integers. I have trouble solving exceptions w.r.t scanf such as some inputs are not integers if there are more/less than 4 inputs if inputs not entered with commas…
user5362313
  • 23
  • 1
  • 3
-5
votes
3 answers

Please tell me why its wrong (LCM & GCD )

Question : Given an array of n numbers, find LCM of it. Since LCM(a,b) = a*b / GCD(a,b), here is my original code: class GFG { // the simple 2 integers recursive to find their GCD. static int getGcd(int a, int b){ while(a != b){ …
吳芯緰
  • 25
  • 1
  • 4
1 2 3
11
12