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

Least Common Multiple - for loop breaks down - javascript

I'm taking a course on FreeCodeCamp.org and the assignment is to find "Smallest Common Multiple". So I came up with a solution I think works and I does up to a certain point. Then the code just seems like it's breaking down. Here is my…
Nikcio
  • 407
  • 1
  • 5
  • 10
1
vote
1 answer

Unexpected Floating point excepction - c++

This program is supposed to compute the smallest common multiple. It does not present divisions by zero, nor weird operations (as far as I know), yet it breaks at some point. The program seems to return "Floating point exception (core dumped)" for…
Álvaro
  • 141
  • 2
  • 14
1
vote
1 answer

PowerShell DSC Local Configuration Manager and mixed Configuration Modes

I”m evaluating DSC, and I have a question about the LCM. I understand that I can use mixedmode with pull/push scenarios, but what about the ConfigurationMode setting for the LCM? I have a situation where the LCM could be set to ApplyandAutoCorrect…
Ian
  • 21
  • 1
1
vote
1 answer

Passing a list to a multiple-arity function in DrRacket (Scheme)

I am trying to generate the least common multiple for all numbers from 1 to n as described in OEIS-A003418. In the DrRacket REPL I'm using the following code: (lcm (apply values (build-list 256 add1))) Which gives me a "result arity mismatch"…
hatch22
  • 797
  • 6
  • 18
1
vote
0 answers

shuffilng array using linear congruent method formula

i need some help here, i'm trying to shuffle an array of question using certain formula(Linear congruent method), but how do i implement them to my arrays? > X(i+1) = (a * X(i) + c) mod M where M is the modulus. M > 0. a is the multiplier, 0 <= a <…
1
vote
3 answers

Sum of numerators of different fractions in Excel

I have an array of cells that contain all numerators (A2:A500) and an array of cells that contain all denominators (B2:B500) think of them as a fraction. Is there a way to put them to the smallest common fraction and sum them up in one line? I can…
Lukas Anda
  • 716
  • 1
  • 9
  • 30
1
vote
2 answers

Q: list assignment index out of range

>>> def lcm(a,b): if a<
1
vote
4 answers

find lowest common multiple

Here I am trying to find lowest common multiple of an array of numbers. I used the following formula to find the value which uses greatest common divisor to find out LCM. My program calculates GCD correctly, but when it comes to find out LCM using…
AL-zami
  • 8,902
  • 15
  • 71
  • 130
1
vote
1 answer

Minimum least common multiplier for random combinations

TLDR: I'm looking for an algo that returns the smallest possible least common multiplier for a variable array of numbers while knowing: one of the numbers the size of my array the min and max values possible for the numbers I’m working with a…
AtActionPark
  • 127
  • 1
  • 8
1
vote
1 answer

Algorithm - GCD and LCM problems

Input for this problem is an array A of positive integers and single positive integer k. The output of the program is True if k is in the set S defined below, False otherwise. Define the set S as follows: if x is in A then x is in S if x and y…
1
vote
1 answer

How to find lcm of multiple numbers using GCD approach?

I'm using the euclidean approach i.e LCM = num1 * num2 / gcd ( num1 , num2 ) I have sucessfully made the code for two numbers but it is buggy if i try it for multiple inputs. my approach can be represented as lcm(a,b,c) = lcm(a,lcm(b,c)) but this…
vishu
  • 23
  • 7
1
vote
1 answer

Find lowest common multiple of many datetime.timedelta objects

Given a list of n timedelta objects, with the lowest denomination of time being minutes, from datetime import timedelta as td [td(days=1, hours=4, minutes=0), td(days=0, hours=2 minutes=30), td(days=3, hours=0 minutes=30), ...] how can I find…
JakeCowton
  • 1,374
  • 5
  • 15
  • 35
1
vote
1 answer

c++ loop for lowest common multiple

I have some problems with this task: you read prom file "perechi.in" a number n and you have to write in a file "perechi.out" how many pairs of numbers have the LCM equal with n. I wrote that code but it crashes and i cannot find out the issue …
Daniel Pop
  • 456
  • 1
  • 6
  • 23
1
vote
2 answers

systems of equations and lowest common multiple

You need 100 lbs of bird feed. John's bag can carry 15 lbs and Mark's bag can carry 25 lbs. Both guys have to contribute exactly the same total amount each. What's the lowest number of trips each will have to take? I have calculated this using…
oneintheword
  • 155
  • 1
  • 7
1
vote
3 answers

What am I doing wrong with this lcm python code?

Here is my code: def gcd(a,b): if a%b == 0: return b print b elif b%a == 0: return a print a else: if a > b: gcd(a%b,b) elif b > a: gcd(b%a,a) else: …
user3103718
  • 63
  • 2
  • 6