問題タブ [lcm]
For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.
algorithm - 3 つ以上の数の最小公倍数
複数の数の最小公倍数をどのように計算しますか?
これまでのところ、2 つの数値の間でしか計算できませんでした。しかし、それを拡張して 3 つ以上の数を計算する方法がわかりません。
これまでのところ、これは私がやった方法です
gcd は、数値の最大公約数を計算する関数です。ユークリッド アルゴリズムの使用
しかし、3つ以上の数の計算方法がわかりません。
algorithm - Finding the LCM of a range of numbers
I read an interesting DailyWTF post today, "Out of All The Possible Answers..." and it interested me enough to dig up the original forum post where it was submitted. This got me thinking how I would solve this interesting problem - the original question is posed on Project Euler as:
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 number that is evenly divisible by all of the numbers from 1 to 20?
To reform this as a programming question, how would you create a function that can find the Least Common Multiple for an arbitrary list of numbers?
I'm incredibly bad with pure math, despite my interest in programming, but I was able to solve this after a little Googling and some experimenting. I'm curious what other approaches SO users might take. If you're so inclined, post some code below, hopefully along with an explanation. Note that while I'm sure libraries exist to compute the GCD and LCM in various languages, I'm more interested in something that displays the logic more directly than calling a library function :-)
I'm most familiar with Python, C, C++, and Perl, but any language you prefer is welcome. Bonus points for explaining the logic for other mathematically-challenged folks out there like myself.
EDIT: After submitting I did find this similar question Least common multiple for 3 or more numbers but it was answered with the same basic code I already figured out and there's no real explanation, so I felt this was different enough to leave open.
optimization - C / x86コードを最適化するにはどうすればよいですか?
上の関数のコードを自分の関数(下)と打ち負かそうとしています。ルーチンを最適化する方法について何かアイデアはありますか?
PS。これはただの楽しみです。
java - 一連の数値でGCD、LCMを見つける方法
一連の数値で最大公約数と最小公倍数を計算する最も簡単な方法は何でしょうか。この情報を見つけるために使用できる数学関数は何ですか?
c++ - 複数の数値の最小公倍数を計算する C++ アルゴリズム
またはのように、複数の数値の最小公倍数を計算する C++ アルゴリズムはありますlcm(3,6,12)
かlcm(5,7,9,12)
?
c - 構造体の複数のvoidポインタを1つのメモリに逆参照するにはどうすればよいですか?
私は特定のIPCスタック(私の場合はLCM)を介して送信する必要があるプロジェクトに取り組んでおり、IPCに可変長構造体を提供する必要があります。私は持っています
pack2へのポインターがあり、シリアル化のようなものが必要なので、これをpack2
ネットワーク経由で別のプロセスに送信できます。
誰もが方法を知っていますか?
c - 2つの数値のLCM
LCMプログラムの結果が間違っています。
最初に数値のgcdを見つけてから、積をgcdで割ります。
どんな助けでも大歓迎です。
greatest-common-divisor - GCD と LCM の関係
次の関係は、2 つの (3, 12) 数値に対してのみ機能します。3 つの数値 (3,12,10) に対して使用すると、正しい答えが得られません。それが私の理解なのか、それとも2つの数値だけなのか、私にとってはユークリッドアルゴリズムにも同じことが当てはまります。
java - 2 つの数値の最小公倍数 (LCM) を見つける方法
ユークリッドの方法を使用して、2 つの数値の最小公倍数を見つけました。
このアルゴリズムを使用せずにこれを行うにはどうすればよいですか? 最初にこれら 2 つの数値のすべての因数を取得し、それらを配列に格納するという考えがあります。次に、配列 1 から 1 つの要素を取得し、配列 2 でそれを検索します。そこに存在する場合は、そこから削除し、結果にその num を掛けます。
これでよろしいですか?
math - ある範囲の数値の GCD と LCM を効率的に取得するには?
現在、このコードを使用してgcdとlcmを見つけています
しかし、[4,5,7,1,5,7,10,1,16,24] などの数値のリストに対してこれを実行したい場合はどうすればよいでしょうか。ループに制約されていますか?