本文へスキップ

リソース · ガイド・記事

Euclidean algorithm

ユークリッドの互除法による最大公約数(GCD)の求め方を、引き算の繰り返しと図形による図解で紹介しています。

確認日

元のサイトを開く: Euclidean algorithm (元のサイトを新しいタブで開きます)

ロードマップに追加

取り組んでいるロードマップにこのリソースを追加できます。自分用の追加リソースとして表示され、ロードマップの手順は変わらず、記録した手順数にも数えられません。

出典コンテンツの言語:英語

In mathematics, the Euclidean algorithm, or Euclid's algorithm, is an efficient method for computing the greatest common divisor (GCD) of two numbers, the largest number that divides both of them without leaving a remainder. The Euclidean algorithm is based on the principle that the greatest common divisor of two numbers does not change if the larger number is replaced by its difference with the smaller number. For example, 21 is the GCD of 252 and 105 (as 252 = 21 × 12 and 105 = 21 × 5), and the same number 21 is also the GCD of 105 and 252 − 105 = 147. Since this replacement reduces the larger of the two numbers, repeating this process gives successively smaller pairs of numbers until the two numbers become equal. When that occurs, they are the GCD of the original two numbers. By reversing the steps, the GCD can be expressed as a sum of the two original numbers each multiplied by a positive or negative integer, e.g., 21 = 5 × 105 + (−2) × 252. The fact that the GCD can always be expressed in this way is known as Bézout's identity.

PrepKit の概要

この概要は PrepKit 編集部がソースリポジトリをもとに執筆・確認したもので、リソース本文の引用ではありません。

対象
ソースにレベルの記載はありません
形式
リファレンス

扱っている内容

  • 大きいほうの数を差で置き換えても GCD は変わらないことを、252 と 105 で示しています
  • ベズーの等式:21 = 5 × 105 + (-2) × 252
  • 24 × 60 の長方形を正方形で敷き詰める図と、1071 と 462 から 21 に至るまで縮めていくアニメーション

使い方

PrepKit の学習アドバイスであり、ソースの主張ではありません。

引き算版と剰余版をコードで書き、1071 と 462 で手順の回数を比べてください。続いて拡張ユークリッドの互除法を加え、ベズーの係数を再現します。

範囲と制約

扱うのは引き算版のみで、剰余を使う形、拡張版、実行時間の説明はありません。

利用方法と形式

GitHub の MIT ライセンスの trekhleb/javascript-algorithms リポジトリにある、英語の無料 README です。

PrepKit が 2026/10/02 に確認しました。 リソースの出典のコミット: 85293e3e2b88

この概要の根拠
  • src/algorithms/math/euclidean-algorithm/README.md

この項目を掲載しているページ

PrepKit ニュースレターを受け取る

任意です。PrepKit の利用には必要ありません。

メールアドレスの取り扱いについて