Skip to content
Back to exploration
Discrete mathematics / Chinese

Greatest common divisor recurrences: subtraction and Euclidean algorithms

南瓜之运 · Bilibili · 4:14

Open original
READ & KEEP

The explanation, unpacked.

Reviewed learning material · Video analysis · English
Read the full overview

The segment first uses a document to present the recurrence formula for the greatest common divisor of two numbers gcd⁡(a,b)=gcd⁡(b,a−k⋅b)\gcd(a,b)=\gcd(b,a-k\cdot b), explaining that the Subtraction Method and the Euclidean Algorithm are special cases for k=1k=1 and k=⌊a/b⌋k=\lfloor a/b\rfloor respectively. It then switches to C++ code, calling `gcd(a,b)` with `a=24a=24` and `b=504b=504`, where the terminal outputs 24, verifying gcd⁡(24,504)=24\gcd(24,504)=24. The instructor also reminds that the demo environment allows direct use of `gcd` due to a newer C++ version, but exam environments may require manual implementation. The clip first uses C++ code to enumerate k=−1024k=-1024 to 10241024, checking whether gcd⁡(24,504)\gcd(24,504) always equals gcd⁡(504,24−k⋅504)\gcd(504,24-k\cdot 504); the terminal only outputs asterisks, indicating no counterexamples in the test range. It then switches to the lecture, presenting the GCD recurrence formula gcd⁡(a,b)=gcd⁡(b,a−k⋅b)\gcd(a,b)=\gcd(b,a-k\cdot b), and explains two special cases: k=1k=1 yields the subtraction-based algorithm gcd⁡(a,b)=gcd⁡(b,a−b)\gcd(a,b)=\gcd(b,a-b), and k=⌊a/b⌋k=\lfloor a/b\rfloor yields the Euclidean algorithm gcd⁡(a,b)=gcd⁡(b,a mod b)\gcd(a,b)=\gcd(b,a\bmod b).

Use the learning inspector for key ideas and moments, or open the reading tabs for the complete notes.

Chapters

0:00Recurrence Formula for GCD of Two Numbers0:15Subtraction Method and Euclidean Algorithm0:38C++ Example: Calculating gcd(24,504)1:12Reminder About C++ Built-in GCD Function2:07Code Enumeration of k to Verify GCD Invariance2:55Recurrence Formula for Greatest Common Divisor3:16Subtraction-based Algorithm: Special Case k=1k=13:32Euclidean Algorithm: Special Case k=⌊a/ba/b⌋

Learning script

Generated from the video's visuals and explanation; not verbatim speech.

The video starts by showing a dark-background document titled "Recurrence Formula for the Greatest Common Divisor of Two Numbers". The instructor first states the goal of this section is to find the recurrence formula for the greatest common divisor of two numbers, emphasizing that for beginners in competitive programming, mastering one core formula is sufficient.

The document gives the core formula: For any integer kk, gcd⁡(a,b)=gcd⁡(b,a−k⋅b)\gcd(a,b)=\gcd(b,a-k\cdot b). Here kk is an arbitrary integer parameter, and a,ba,b are the two integers whose greatest common divisor is being sought.

Next, the document specializes the formula into two common methods. First set k=1k=1, obtaining the subtraction method: gcd⁡(a,b)=gcd⁡(b,a−b)\gcd(a,b)=\gcd(b,a-b). In a−k⋅ba-k\cdot b, this step replaces the kk with 1.

Second, let k=⌊a/b⌋k=\lfloor a/b\rfloor, yielding the Euclidean Algorithm: gcd⁡(a,b)=gcd⁡(b,a mod b)\gcd(a,b)=\gcd(b,a\bmod b). The video directly gives this conclusion; supplementarily, it is usually because a mod b=a−⌊a/b⌋ba\bmod b=a-\lfloor a/b\rfloor b.

The screen then switches to a C++ code editor. The instructor starts giving a numerical example, declaring `const int a=24a = 24;` and `const int b=504b = 504;` in the `main` function, preparing to calculate the greatest common divisor of these two integers.

The code writes `cout << gcd(a, b) << endl;` and runs. The terminal outputs `24`, thus the example verifies gcd⁡(24,504)=24\gcd(24,504)=24. The instructor also verbally confirms "The result is 24".

The instructor explains that writing `gcd(a,b)` directly here is possible because the C++ version he uses is relatively new, and the environment comes with the function built-in. However, he immediately reminds that the C++ compiler version during exams might not be this new, and one might need to implement the gcd function themselves at that time.

Afterwards, for a=24,b=504a=24,b=504, the instructor records the greatest common divisor answer as 24 and adds `const int c = gcd(a, b);` to prepare for the next discussion.

At the end of the segment, the instructor returns to the range of parameter kk, saying one can let kk go from negative 1024 to positive 1024, and writes `for (int k=−1024k=-1024;k<=1024;++k)` in the code. He begins asking if there exists some kk such that gcd⁡(b,a−k⋅b)\gcd(b,a-k\cdot b) satisfies subsequent conditions, but the sentence is not finished before the segment ends.

On the left is a C++ program in VS Code, on the right is the terminal. The code sets `const int a=24a = 24;`, `const int b=504b = 504;`, `const int c = gcd(a, b);`, then iterates integer kk using `for (int k=−1024k=-1024; k<=1024; ++k)`. Inside the loop, it checks `if (c != gcd(b, a−k∗ba - k * b))`, printing the current kk if they are not equal.

To mark the complete execution of the program, `cout << "**********" << endl;` is added at the end. The narrator explains that these asterisks are just a marker for program completion.

After recompiling and running, the terminal only displays `**********`, with no kk shown. Since the program only prints kk when `c != gcd(b, a−k∗ba - k * b)`, this indicates no counterexamples were found in the test range −1024≤k≤1024-1024\le k\le 1024.

Based on this, the narrator concludes: For any integer kk, gcd⁡(a,b)=gcd⁡(b,a−k⋅b)\gcd(a,b)=\gcd(b,a-k\cdot b) always holds. The mathematical content here is that the greatest common divisor remains invariant after replacing the first argument with a−kba-kb and swapping the argument order.

The screen switches to a black-background white-text lecture titled "1 Recurrence Formula for GCD of Two Numbers". The text states "For any integer kk: gcd⁡(a,b)=gcd⁡(b,a−k⋅b)\gcd(a,b)=\gcd(b,a-k\cdot b)". This is the core recurrence formula of this clip.

The lecture continues to show two special cases. Section 1.1 "Subtraction-based Algorithm" reads: "Let k=1k=1, we get the subtraction-based algorithm: gcd⁡(a,b)=gcd⁡(b,a−b)\gcd(a,b)=\gcd(b,a-b)." This step simply substitutes kk with 1 in the general formula, so a−kba-kb becomes a−ba-b.

Section 1.2 "Euclidean Algorithm" reads: "Let k=⌊a/b⌋k=\lfloor a/b\rfloor, we get the Euclidean algorithm: gcd⁡(a,b)=gcd⁡(b,a mod b)\gcd(a,b)=\gcd(b,a\bmod b)." The narrator explains that ⌊a/b⌋\lfloor a/b\rfloor is the quotient of aa divided by bb, so a−⌊a/b⌋ba-\lfloor a/b\rfloor b is the dividend minus quotient times divisor, i.e., the remainder a mod ba\bmod b.

On screen, the pink annotation writes a−k⋅ba-k\cdot b first and places a−⌊a/b⌋ba-\lfloor a/b\rfloor b above it, with an arrow to a mod ba\bmod b below. This connects the general recurrence to the Euclidean algorithm and shows that the latter is the special case k=⌊a/b⌋k=\lfloor a/b\rfloor.

Knowledge cards

01

Recurrence Formula for GCD of Two Numbers

The core formula given in the video is: For any integer kk, gcd⁡(a,b)=gcd⁡(b,a−k⋅b)\gcd(a,b)=\gcd(b,a-k\cdot b). The instructor emphasizes this is the key recurrence relationship to master for finding the greatest common divisor of two numbers.

gcd⁡(a,b)=gcd⁡(b,a−k⋅b)\gcd(a,b)=\gcd(b,a-k\cdot b)
02

Subtraction Method

Letting k=1k=1 in the core formula yields gcd⁡(a,b)=gcd⁡(b,a−b)\gcd(a,b)=\gcd(b,a-b). This is the Subtraction Method labeled in the document, essentially replacing one parameter with the difference of the two numbers each time.

gcd⁡(a,b)=gcd⁡(b,a−b)\gcd(a,b)=\gcd(b,a-b)
03

Euclidean Algorithm

Letting k=⌊a/b⌋k=\lfloor a/b\rfloor in the core formula, the document directly gives gcd⁡(a,b)=gcd⁡(b,a mod b)\gcd(a,b)=\gcd(b,a\bmod b). Supplementary explanation: Usually because a mod b=a−⌊a/b⌋ba\bmod b=a-\lfloor a/b\rfloor b, it is also a special case of the core formula.

gcd⁡(a,b)=gcd⁡(b,a mod b)\gcd(a,b)=\gcd(b,a\bmod b)
04

Example gcd(24,504)

The video sets `a=24a=24` and `b=504b=504` in C++ code, calls `gcd(a,b)` and outputs the result. The terminal displays `24`, thus the example verifies gcd⁡(24,504)=24\gcd(24,504)=24.

gcd⁡(24,504)=24\gcd(24,504)=24
05

Reminder on Using C++ Built-in GCD

The instructor explains that the demo environment can call `gcd(a,b)` directly because the C++ version used is relatively new; however, the compiler version in exam environments might be older, so one cannot assume the function definitely exists and may need to implement it manually if necessary.

06

GCD Recurrence Formula

The core formula presented in the video is: For any integer kk, gcd⁡(a,b)=gcd⁡(b,a−k⋅b)\gcd(a,b)=\gcd(b,a-k\cdot b). It states that when calculating the greatest common divisor of two integers, one argument can be replaced by the integer multiple difference of the other argument, and swapping argument positions leaves the result unchanged. The code example uses a=24a=24, b=504b=504, and k∈[−1024,1024]k\in[-1024,1024] for enumeration testing, with the terminal outputting no counterexample kk.

gcd⁡(a,b)=gcd⁡(b,a−k⋅b)\gcd(a,b)=\gcd(b,a-k\cdot b)
07

Subtraction-based Algorithm

The subtraction-based algorithm is a special case of the recurrence formula gcd⁡(a,b)=gcd⁡(b,a−k⋅b)\gcd(a,b)=\gcd(b,a-k\cdot b) when k=1k=1. After substituting k=1k=1, the second argument a−kba-kb becomes a−ba-b, yielding gcd⁡(a,b)=gcd⁡(b,a−b)\gcd(a,b)=\gcd(b,a-b). Lecture section 1.1 explicitly writes out this derivation.

gcd⁡(a,b)=gcd⁡(b,a−b)\gcd(a,b)=\gcd(b,a-b)
08

Euclidean Algorithm

The Euclidean algorithm is a special case of the recurrence formula gcd⁡(a,b)=gcd⁡(b,a−k⋅b)\gcd(a,b)=\gcd(b,a-k\cdot b) when k=⌊a/b⌋k=\lfloor a/b\rfloor. At this point, a−kb=a−⌊a/b⌋ba-kb=a-\lfloor a/b\rfloor b, which the narrator explains is the dividend minus quotient times divisor, equal to the remainder a mod ba\bmod b, thus yielding gcd⁡(a,b)=gcd⁡(b,a mod b)\gcd(a,b)=\gcd(b,a\bmod b). The video does not explicitly state that division requires b≠0b\neq0.

gcd⁡(a,b)=gcd⁡(b,a mod b)\gcd(a,b)=\gcd(b,a\bmod b)
09

Code Verification of GCD Invariance

The code first sets a=24a=24, b=504b=504, c=gcd⁡(a,b)c=\gcd(a,b), then iterates k=−1024k=-1024 to 10241024. If c≠gcd⁡(b,a−kb)c\neq\gcd(b,a-kb) occurs, the program prints that kk; after the loop ends, it prints `**********` as a completion marker. The terminal only displays `**********`, indicating no counterexamples were found in the test range.

Detailed learning notes

Explore conditions, steps and evidence. Supplementary explanations are labeled separately from content shown in the video.

Symbols · 14

gcd⁡\gcd

Clear evidence
Shown in the video
Evidence
  1. Formula
    Observation

    The document repeatedly shows gcd⁡(a,b)\gcd(a,b), and the code calls gcd⁡(a,b)\gcd(a,b).

  2. Audio
    Observation

    The instructor says "greatest common divisor" multiple times.

Symbol

gcd⁡\gcd

Meaning

The greatest common divisor function for two integers.

Domain

The video does not specify the exact domain; non-negative integers are used in the examples.

a,ba,b

Clear evidence
Shown in the video
Evidence
  1. Formula
    Observation

    The document formula is written as gcd⁡(a,b)=gcd⁡(b,a−k⋅b)\gcd(a,b)=\gcd(b,a-k\cdot b).

  2. Formula
    Observation

    The code declares `const int a=24a = 24;` and `const int b=504b = 504;`.

Symbol

a,ba,b

Meaning

The two integers involved in finding the greatest common divisor.

Domain

Integers in the example; the video does not give general restrictions.

kk

Clear evidence
Shown in the video
Evidence
  1. Formula
    Observation

    The document states "For any integer kk: gcd⁡(a,b)=gcd⁡(b,a−k⋅b)\gcd(a,b)=\gcd(b,a-k\cdot b)."

  2. Audio
    Observation

    The instructor says "First let kk be an arbitrary integer."

  3. Formula
    Observation

    The code loop is written as `for (int k=−1024k=-1024;k<=1024;++k)`.

Symbol

kk

Meaning

An arbitrary integer parameter in the recurrence formula.

Domain

Any integer.

a mod ba\bmod b

Clear evidence
Shown in the video
Evidence
  1. Formula
    Observation

    The document writes gcd⁡(a,b)=gcd⁡(b,a mod b)\gcd(a,b)=\gcd(b,a\bmod b).

Uncertainties
  1. The video does not explain the definition of `mod`, sign conventions, or handling when b=0b=0.

Symbol

a mod ba\bmod b

Meaning

The remainder term in the Euclidean algorithm formula.

Domain

Not specified in the video.

⌊a/b⌋\lfloor a/b\rfloor

Clear evidence
Shown in the video
Evidence
  1. Formula
    Observation

    The document writes "Let k=⌊a/b⌋k=\lfloor a/b\rfloor."

Uncertainties
  1. The video does not state that this expression is undefined when b=0b=0.

Symbol

⌊a/b⌋\lfloor a/b\rfloor

Meaning

The integer quotient obtained by taking the floor of a/ba/b.

Domain

Not specified in the video.

`int`

Clear evidence
Shown in the video
Evidence
  1. Formula
    Observation

    The code contains `const int a=24a = 24;`, `const int b=504b = 504;`, and `for (int k=−1024k=-1024;k<=1024;++k)`.

Symbol

`int`

Meaning

The integer type used in C++ to declare the example variables.

Domain

The video does not specify the range of values.

`gcd(a, b)`

Clear evidence
Shown in the video
Evidence
  1. Formula
    Observation

    The code writes `cout << gcd(a, b) << endl;`.

  2. Audio
    Observation

    The instructor says "I directly used the gcd function here... my C++ version is relatively new now, so it comes with the gcd function built-in."

Uncertainties
  1. The video does not specify which standard library header file is used; the screen shows `#include <bits/stdc++.h>`.

Symbol

`gcd(a, b)`

Meaning

A call to the greatest common divisor function in C++ code.

Domain

Two `int` values are passed in the example.

a

Clear evidence
Shown in the video
Evidence
  1. Formula
    Observation

    Code line 6 `const int a=24a = 24;`; Lecture section 1 formula gcd⁡(a,b)=gcd⁡(b,a−k⋅b)\gcd(a,b)=\gcd(b,a-k\cdot b) contains aa

  2. Audio
    Observation

    When deriving k=⌊a/b⌋k=\lfloor a/b\rfloor, the narrator calls it “the quotient of aa divided by bb.”

Symbol

a

Meaning

The first integer participating in the greatest common divisor calculation; takes the value 24 in the code example

Domain

Integer

b

Clear evidence
Shown in the video
Evidence
  1. Formula
    Observation

    Code line 7 `const int b=504b = 504;`; Lecture section 1 formula gcd⁡(a,b)=gcd⁡(b,a−k⋅b)\gcd(a,b)=\gcd(b,a-k\cdot b) contains bb

  2. Audio
    Observation

    The narrator says "aa divided by bb, rounded down"

Symbol

b

Meaning

The second integer participating in the greatest common divisor calculation; takes the value 504 in the code example

Domain

Integer

c

Clear evidence
Shown in the video
Evidence
  1. Formula
    Observation

    Code line 8 `const int c = gcd(a, b);`; Line 11 `if (c != gcd(b, a−k∗ba - k * b))`

  2. Audio
    Observation

    The narrator says "if c is not equal to it"

Symbol

c

Meaning

Variable in the code storing the result of gcd⁡(a,b)\gcd(a,b)

Domain

Integer

k

Clear evidence
Shown in the video
Evidence
  1. Formula
    Observation

    Code line 10 `for (int k=−1024k=-1024; k<=1024; ++k)`; Lecture section 1 "For any integer kk: gcd⁡(a,b)=gcd⁡(b,a−k⋅b)\gcd(a,b)=\gcd(b,a-k\cdot b)"

  2. Audio
    Observation

    The narrator says "for any kk", "for example when kk equals 1", "let kk equal aa divided by bb, rounded down"

Symbol

k

Meaning

Integer parameter in the recurrence formula; iteration range in code is -1024 to 1024

Domain

Integer

gcd⁡\gcd

Clear evidence
Shown in the video
Evidence
  1. Formula
    Observation

    Code line 8 `gcd(a, b)`; Lecture section 1 formula gcd⁡(a,b)=gcd⁡(b,a−k⋅b)\gcd(a,b)=\gcd(b,a-k\cdot b)

  2. Audio
    Observation

    The narrator reads "gcd a b equals gcd b a minus k times b"

Symbol

gcd⁡\gcd

Meaning

Greatest common divisor function

Domain

Operates on two integers, returns an integer

Knowledge points · 7

Recurrence Formula for GCD of Two Numbers

Clear evidence
Shown in the video
Evidence
  1. Formula
    Observation

    The document title is "Recurrence Formula for the Greatest Common Divisor of Two Numbers".

  2. Formula
    Observation

    The document body states "For any integer kk: gcd⁡(a,b)=gcd⁡(b,a−k⋅b)\gcd(a,b)=\gcd(b,a-k\cdot b)."

  3. Audio
    Observation

    The instructor says, “This time we will discuss the recurrence formula for the greatest common divisor of two numbers,” and “First let kk be an arbitrary integer; then the greatest common divisor of aa and bb equals the greatest common divisor of b,ab, a minus kk times bb.”

Formula
Explanation

The core formula given in the video transforms gcd⁡(a,b)\gcd(a,b) into gcd⁡(b,a−k⋅b)\gcd(b,a-k\cdot b), where kk can be any integer. The instructor emphasizes that for beginners in competitive programming, mastering this single formula is sufficient.

Formula
gcd⁡(a,b)=gcd⁡(b,a−k⋅b)\gcd(a,b)=\gcd(b,a-k\cdot b)
Conditions
  1. kk is any integer.

  2. The video does not specify additional restrictions on a,ba,b.

Subtraction Method

Clear evidence
Shown in the video
Evidence
  1. Formula
    Observation

    The document subsection title is "1.1 Subtraction Method".

  2. Formula
    Observation

    The document writes "Let k=1k=1, to get the Subtraction Method: gcd⁡(a,b)=gcd⁡(b,a−b)\gcd(a,b)=\gcd(b,a-b)."

Method
Explanation

This is a special case of the core recurrence formula when k=1k=1, replacing the first parameter with the difference of the two numbers each time.

Formula
gcd⁡(a,b)=gcd⁡(b,a−b)\gcd(a,b)=\gcd(b,a-b)
Conditions
  1. Derived from the core formula by letting k=1k=1.

  2. The video does not specify size relationships or sign restrictions for a,ba,b.

Prerequisites
  1. Recurrence Formula for GCD of Two Numbers

Euclidean Algorithm

Clear evidence
Shown in the video
Evidence
  1. Formula
    Observation

    The document subsection title is "1.2 Euclidean Algorithm".

  2. Formula
    Observation

    The document writes "Let k=⌊a/b⌋k=\lfloor a/b\rfloor, to get the Euclidean Algorithm: gcd⁡(a,b)=gcd⁡(b,a mod b)\gcd(a,b)=\gcd(b,a\bmod b)."

Uncertainties
  1. The video does not explain the definition of `mod`, handling of b=0b=0, or the relationship between the floor quotient and remainder.

Method
Explanation

This is a special case of the core recurrence formula when k=⌊a/b⌋k=\lfloor a/b\rfloor, replacing the first parameter with the remainder of aa divided by bb.

Formula
gcd⁡(a,b)=gcd⁡(b,a mod b)\gcd(a,b)=\gcd(b,a\bmod b)
Conditions
  1. Derived from the core formula by letting k=⌊a/b⌋k=\lfloor a/b\rfloor.

  2. The video does not mention the usual prerequisite b≠0b\neq 0.

Prerequisites
  1. Recurrence Formula for GCD of Two Numbers

Directly Calling gcd Function in C++

Clear evidence
Shown in the video
Evidence
  1. Formula
    Observation

    The code calls `gcd(a, b)`.

  2. Audio
    Observation

    The instructor says "I directly used the gcd function here because my C++ version is relatively new now, so it comes with the gcd function built-in."

  3. Audio
    Observation

    The instructor also says "But during exams, the C++ compiler version might not be this new, so you may need to implement the gcd function yourself during exams. We will discuss how to implement it later."

Uncertainties
  1. The video does not specify the exact C++ standard version or header file; the screen shows `#include <bits/stdc++.h>`.

Method
Explanation

The video demonstrates calling `gcd(a,b)` directly in a newer C++ environment to calculate the greatest common divisor, while reminding that exam environments may not support this built-in function and require manual implementation.

Formula
cout<<gcd(a,b)<<endl;cout << gcd(a, b) << endl;
Conditions
  1. The video states the current C++ version is relatively new.

  2. The video does not specify the exact standard version.

Recurrence Formula for GCD of Two Numbers

Clear evidence
Shown in the video
Evidence
  1. Formula
    Observation

    Lecture title "1 Recurrence Formula for GCD of Two Numbers"; Text "For any integer kk: gcd⁡(a,b)=gcd⁡(b,a−k⋅b)\gcd(a,b)=\gcd(b,a-k\cdot b)"

  2. Audio
    Observation

    The narrator says "For any kk, gcd a b equals gcd b a minus kk times bb, always holds", "The first systematic professional recurrence formula we need to master"

Formula
Explanation

The video presents the recurrence identity for the greatest common divisor: for any integer kk, gcd⁡(a,b)=gcd⁡(b,a−k⋅b)\gcd(a,b)=\gcd(b,a-k\cdot b). This formula transforms the GCD of (a,b)(a,b) into the GCD of (b,a−kb)(b,a-kb), serving as the unified source for the subsequent subtraction-based algorithm and the Euclidean algorithm.

Formula
gcd⁡(a,b)=gcd⁡(b,a−k⋅b)\gcd(a,b)=\gcd(b,a-k\cdot b)
Conditions
  1. a,ba,b are integers

  2. kk is any integer

Subtraction-based Algorithm as a Special Case of the Recurrence Formula

Clear evidence
Shown in the video
Evidence
  1. Formula
    Observation

    Lecture section 1.1 "Subtraction-based Algorithm"; "Let k=1k=1, we get the subtraction-based algorithm: gcd⁡(a,b)=gcd⁡(b,a−b)\gcd(a,b)=\gcd(b,a-b)"

  2. Audio
    Observation

    The narrator says "For example, when kk equals 1, we get gcd a b equals gcd b a minus b, this is the famous subtraction-based algorithm"

Method
Explanation

In the recurrence formula gcd⁡(a,b)=gcd⁡(b,a−k⋅b)\gcd(a,b)=\gcd(b,a-k\cdot b), set k=1k=1 to obtain gcd⁡(a,b)=gcd⁡(b,a−b)\gcd(a,b)=\gcd(b,a-b). The video names this special case the subtraction-based algorithm.

Formula
gcd⁡(a,b)=gcd⁡(b,a−b)\gcd(a,b)=\gcd(b,a-b)
Conditions
  1. k=1k=1

  2. a,ba,b are integers

Prerequisites
  1. Recurrence Formula for GCD of Two Numbers

Euclidean Algorithm as a Special Case of the Recurrence Formula

Clear evidence
Shown in the video
Evidence
  1. Formula
    Observation

    Lecture section 1.2 "Euclidean Algorithm"; "Let k=⌊a/b⌋k=\lfloor a/b\rfloor, we get the Euclidean algorithm: gcd⁡(a,b)=gcd⁡(b,a mod b)\gcd(a,b)=\gcd(b,a\bmod b)"

  2. Audio
    Observation

    The narrator says "If we let kk equal aa divided by bb, rounded down... we get gcd a b equals gcd b a modulo b remainder, this is the famous Euclidean algorithm"

Method
Explanation

In the recurrence formula gcd⁡(a,b)=gcd⁡(b,a−k⋅b)\gcd(a,b)=\gcd(b,a-k\cdot b), set k=⌊a/b⌋k=\lfloor a/b\rfloor. Then a−kb=a−(⌊a/b⌋)ba-kb=a-(\lfloor a/b\rfloor)b is the remainder of aa divided by bb, giving gcd⁡(a,b)=gcd⁡(b,a mod b)\gcd(a,b)=\gcd(b,a\bmod b). The video names this special case the Euclidean algorithm.

Formula
gcd⁡(a,b)=gcd⁡(b,a mod b)\gcd(a,b)=\gcd(b,a\bmod b)
Conditions
  1. k=⌊a/b⌋k=\lfloor a/b\rfloor

  2. a,ba,b are integers

  3. Video does not state b≠0b\neq 0

Prerequisites
  1. Recurrence Formula for GCD of Two Numbers
Claims and conditions · 8

GCD Recurrence Identity for Any Integer k

Clear evidence
Shown in the video
Evidence
  1. Formula
    Observation

    The document writes "For any integer kk: gcd⁡(a,b)=gcd⁡(b,a−k⋅b)\gcd(a,b)=\gcd(b,a-k\cdot b)."

  2. Audio
    Observation

    The instructor repeats the formula and says "It is this formula."

Uncertainties
  1. The video does not provide a proof.

Proposition
Statement

For any integer kk, gcd⁡(a,b)=gcd⁡(b,a−k⋅b)\gcd(a,b)=\gcd(b,a-k\cdot b).

Hypotheses
  1. kk is any integer.

  2. The video does not specify additional restrictions on a,ba,b.

Quantifiers

Holds for any integer kk.

Subtraction Method is a Special Case of the Core Formula

Clear evidence
Shown in the video
Evidence
  1. Formula
    Observation

    The document writes "Let k=1k=1, to get the Subtraction Method: gcd⁡(a,b)=gcd⁡(b,a−b)\gcd(a,b)=\gcd(b,a-b)."

Proposition
Statement

When k=1k=1, the core recurrence formula becomes gcd⁡(a,b)=gcd⁡(b,a−b)\gcd(a,b)=\gcd(b,a-b).

Hypotheses
  1. The core formula holds.

  2. Take k=1k=1.

Quantifiers

Direct substitution within the formula framework given in the video.

Euclidean Algorithm is a Special Case of the Core Formula

Clear evidence
Shown in the video
Evidence
  1. Formula
    Observation

    The document writes "Let k=⌊a/b⌋k=\lfloor a/b\rfloor, to get the Euclidean Algorithm: gcd⁡(a,b)=gcd⁡(b,a mod b)\gcd(a,b)=\gcd(b,a\bmod b)."

Uncertainties
  1. The video does not specify b≠0b\neq 0 nor the precise definition of `mod`.

Proposition
Statement

When k=⌊a/b⌋k=\lfloor a/b\rfloor, the core recurrence formula becomes gcd⁡(a,b)=gcd⁡(b,a mod b)\gcd(a,b)=\gcd(b,a\bmod b).

Hypotheses
  1. The core formula holds.

  2. Take k=⌊a/b⌋k=\lfloor a/b\rfloor.

  3. Usually requires b≠0b\neq 0, though not stated in the video.

Quantifiers

Direct substitution within the formula framework given in the video.

Value of gcd(24,504) in the Example

Clear evidence
Shown in the video
Evidence
  1. Formula
    Observation

    The code has `const int a=24a = 24;` and `const int b=504b = 504;`.

  2. Formula
    Observation

    The terminal outputs `24`.

  3. Audio
    Observation

    The instructor says "The result is 24" and "When a=24,b=504a=24, b=504, their greatest common divisor answer is 24."

Proposition
Statement

In this example, gcd⁡(24,504)=24\gcd(24,504)=24.

Hypotheses
  1. a=24a=24.

  2. b=504b=504.

Quantifiers

For the given numerical instance.

Exam Environments May Require Manual GCD Implementation

Clear evidence
Shown in the video
Evidence
  1. Audio
    Observation

    The instructor says "But during exams, the C++ compiler version might not be this new, so you may need to implement the gcd function yourself during exams."

Uncertainties
  1. The video does not specify the exact exam platform or compiler version.

Proposition
Statement

The video warns that the C++ compiler version in exams might be older, so one cannot assume the `gcd` function is available and must be prepared to implement it manually.

Hypotheses
  1. The C++ compiler version in the exam environment might not be as new as the demo environment.

Quantifiers

Stated as a general warning in the video, without formal quantifiers.

GCD Remains Invariant for Any Integer k

Clear evidence
Shown in the video
Evidence
  1. Audio
    Observation

    The narrator says "That is to say, for any kk, gcd a b equals gcd b a minus kk times bb, always holds"

  2. Formula
    Observation

    Lecture section 1 writes "For any integer kk: gcd⁡(a,b)=gcd⁡(b,a−k⋅b)\gcd(a,b)=\gcd(b,a-k\cdot b)"

  3. Diagram
    Observation

    After running the program in the terminal, only `**********` is output, with no kk satisfying the condition `c != gcd(b, a−k∗ba - k * b)`

Proposition
Statement

For any integer kk, gcd⁡(a,b)=gcd⁡(b,a−k⋅b)\gcd(a,b)=\gcd(b,a-k\cdot b) holds.

Hypotheses
  1. a,ba,b are integers

  2. kk is any integer

Quantifiers

Any integer kk

Recurrence Formula Reduces to Subtraction-based Algorithm when k=1k=1

Clear evidence
Shown in the video
Evidence
  1. Formula
    Observation

    Lecture section 1.1 "Let k=1k=1, we get the subtraction-based algorithm: gcd⁡(a,b)=gcd⁡(b,a−b)\gcd(a,b)=\gcd(b,a-b)"

  2. Audio
    Observation

    The narrator says "When kk equals 1, we get gcd a b equals gcd b a minus b, this is the famous subtraction-based algorithm"

Proposition
Statement

Letting k=1k=1, the recurrence formula gcd⁡(a,b)=gcd⁡(b,a−k⋅b)\gcd(a,b)=\gcd(b,a-k\cdot b) reduces to gcd⁡(a,b)=gcd⁡(b,a−b)\gcd(a,b)=\gcd(b,a-b).

Hypotheses
  1. a,ba,b are integers

  2. k=1k=1

Quantifiers

Existence of specific value k=1k=1

Recurrence Formula Reduces to Euclidean Algorithm when k=⌊a/ba/b⌋

Clear evidence
Shown in the video
Evidence
  1. Formula
    Observation

    Lecture section 1.2 "Let k=⌊a/b⌋k=\lfloor a/b\rfloor, we get the Euclidean algorithm: gcd⁡(a,b)=gcd⁡(b,a mod b)\gcd(a,b)=\gcd(b,a\bmod b)"

  2. Audio
    Observation

    The narrator says "If we let kk equal aa divided by bb, rounded down... we get gcd a b equals gcd b a modulo b remainder, this is the famous Euclidean algorithm"

Uncertainties
  1. Video does not explicitly state the division prerequisite b≠0b\neq 0

Proposition
Statement

Letting k=⌊a/b⌋k=\lfloor a/b\rfloor, then a−kb=a mod ba-kb=a\bmod b, thus gcd⁡(a,b)=gcd⁡(b,a mod b)\gcd(a,b)=\gcd(b,a\bmod b).

Hypotheses
  1. a,ba,b are integers

  2. k=⌊a/b⌋k=\lfloor a/b\rfloor

  3. Video does not state b≠0b\neq 0

Quantifiers

Existence of specific value k=⌊a/b⌋k=\lfloor a/b\rfloor

Derivations and proofs · 6

Deriving Subtraction Method from Core Formula

Clear evidence
Shown in the video
Evidence
  1. Formula
    Observation

    The document first gives gcd⁡(a,b)=gcd⁡(b,a−k⋅b)\gcd(a,b)=\gcd(b,a-k\cdot b), then writes "Let k=1k=1, to get the Subtraction Method: gcd⁡(a,b)=gcd⁡(b,a−b)\gcd(a,b)=\gcd(b,a-b)."

Intuitive argument
Steps
  1. Expression
    gcd⁡(a,b)=gcd⁡(b,a−k⋅b)\gcd(a,b)=\gcd(b,a-k\cdot b)
    Explanation

    Start from the core recurrence formula given in the video.

    Justification

    The document directly provides this formula.

    Shown in the video
  2. Expression
    k=1k=1
    Explanation

    Set the parameter kk to 1.

    Justification

    The document writes "Let k=1k=1."

    Shown in the video
  3. Expression
    gcd⁡(a,b)=gcd⁡(b,a−b)\gcd(a,b)=\gcd(b,a-b)
    Explanation

    Substitute to get the form of the Subtraction Method.

    Justification

    Substitute k=1k=1 into the equality a−k⋅b=a−ba-k\cdot b=a-b.

    Derived from the video
Conclusion

The Subtraction Method gcd⁡(a,b)=gcd⁡(b,a−b)\gcd(a,b)=\gcd(b,a-b) is a special case of the core recurrence formula when k=1k=1.

Deriving Euclidean Algorithm from Core Formula

Clear evidence
Shown in the video
Evidence
  1. Formula
    Observation

    The document first gives gcd⁡(a,b)=gcd⁡(b,a−k⋅b)\gcd(a,b)=\gcd(b,a-k\cdot b), then writes "Let k=⌊a/b⌋k=\lfloor a/b\rfloor, to get the Euclidean Algorithm: gcd⁡(a,b)=gcd⁡(b,a mod b)\gcd(a,b)=\gcd(b,a\bmod b)."

Uncertainties
  1. The video does not show the intermediate explanation from a−⌊a/b⌋ba-\lfloor a/b\rfloor b to a mod ba\bmod b.

Intuitive argument
Steps
  1. Expression
    gcd⁡(a,b)=gcd⁡(b,a−k⋅b)\gcd(a,b)=\gcd(b,a-k\cdot b)
    Explanation

    Start from the core recurrence formula given in the video.

    Justification

    The document directly provides this formula.

    Shown in the video
  2. Expression
    k=⌊a/b⌋k=\lfloor a/b\rfloor
    Explanation

    Set the parameter kk to the floor of a/ba/b.

    Justification

    The document writes "Let k=⌊a/b⌋k=\lfloor a/b\rfloor."

    Shown in the video
  3. Expression
    gcd⁡(a,b)=gcd⁡(b,a mod b)\gcd(a,b)=\gcd(b,a\bmod b)
    Explanation

    Substitute to get the form of the Euclidean Algorithm.

    Justification

    The document directly gives this conclusion; supplementary explanation: usually because a mod b=a−⌊a/b⌋ba\bmod b=a-\lfloor a/b\rfloor b.

    Shown in the video
Conclusion

The Euclidean Algorithm gcd⁡(a,b)=gcd⁡(b,a mod b)\gcd(a,b)=\gcd(b,a\bmod b) is a special case of the core recurrence formula when k=⌊a/b⌋k=\lfloor a/b\rfloor.

Numerical Verification gcd(24,504)=24

Clear evidence
Shown in the video
Evidence
  1. Formula
    Observation

    The code sets `const int a=24a = 24;` and `const int b=504b = 504;`.

  2. Formula
    Observation

    The terminal outputs `24`.

  3. Audio
    Observation

    The instructor says "The result is 24."

Numerical verification
Steps
  1. Expression
    a=24,b=504a=24,\quad b=504
    Explanation

    Set the example values.

    Justification

    These constants are declared in the code.

    Shown in the video
  2. Expression
    gcd⁡(24,504)\gcd(24,504)
    Explanation

    Call the greatest common divisor function to calculate the example value.

    Justification

    The code writes `cout << gcd(a, b) << endl;`.

    Shown in the video
  3. Expression
    2424
    Explanation

    The program output is 24.

    Justification

    The terminal displays `24`, and the instructor confirms it verbally.

    Shown in the video
Conclusion

For the example values a=24,b=504a=24, b=504, the video verifies gcd⁡(24,504)=24\gcd(24,504)=24 through program output.

Verifying GCD Recurrence Invariance via Code Enumeration of k

Clear evidence
Shown in the video
Evidence
  1. Formula
    Observation

    Code lines 6-12: `const int a=24a = 24; const int b=504b = 504; const int c = gcd(a, b); for (int k=−1024k=-1024; k<=1024; ++k) { if (c != gcd(b, a−k∗ba - k * b)) { cout << k << endl; } }`

  2. Diagram
    Observation

    Terminal at seconds 31-33 shows compilation and execution output `**********`, with no kk values output

  3. Audio
    Observation

    The narrator says "You will find that this program only outputs a bunch of asterisks", "That is to say, for any kk, gcd a b equals gcd b a minus kk times bb, always holds"

Uncertainties
  1. Code defines `#define int int64_t` redefining `int` as 64-bit integer, but video does not explain its impact on the example's numerical range

Numerical verification
Steps
  1. Expression
    a=24, b=504, c=gcd⁡(a,b)a=24,\ b=504,\ c=\gcd(a,b)
    Explanation

    The code first fixes a=24a=24, b=504b=504, and stores gcd⁡(a,b)\gcd(a,b) in variable cc.

    Justification

    Directly given by code lines 6-8 in the video.

    Shown in the video
  2. Expression
    for k=−1024,−1023,…,1024: check c≠gcd⁡(b,a−kb)\text{for }k=-1024,-1023,\ldots,1024:\ \text{check } c\neq \gcd(b,a-kb)
    Explanation

    The program iterates integer kk from -1024 to 1024, checking whether gcd⁡(a,b)\gcd(a,b) is not equal to gcd⁡(b,a−kb)\gcd(b,a-kb).

    Justification

    Directly given by code lines 10-11 in the video.

    Shown in the video
  3. Expression
    output only ∗∗∗∗∗∗∗∗∗∗\text{output only } **********
    Explanation

    The execution result shows no kk satisfying `c != gcd(b, a−k∗ba - k * b)`, only outputting the asterisk marker after the loop ends.

    Justification

    Terminal output at seconds 31-33 shows `**********`.

    Shown in the video
  4. Expression
    gcd⁡(24,504)=gcd⁡(504,24−k⋅504) for tested k\gcd(24,504)=\gcd(504,24-k\cdot 504)\ \text{for tested } k
    Explanation

    Since no counterexample was found within the test range, the narrator concludes that the recurrence equality holds for any integer kk.

    Justification

    Narrator summarizes at seconds 39-48 "For any kk... always holds".

    Shown in the video
Conclusion

Code enumeration verification supports gcd⁡(a,b)=gcd⁡(b,a−kb)\gcd(a,b)=\gcd(b,a-kb) having no counterexamples within the test range, which the narrator generalizes to hold for any integer kk.

Deriving Subtraction-based Algorithm by Substituting k=1k=1 into General Recurrence Formula

Clear evidence
Shown in the video
Evidence
  1. Formula
    Observation

    Lecture section 1 gcd⁡(a,b)=gcd⁡(b,a−k⋅b)\gcd(a,b)=\gcd(b,a-k\cdot b); Section 1.1 "Let k=1k=1, we get the subtraction-based algorithm: gcd⁡(a,b)=gcd⁡(b,a−b)\gcd(a,b)=\gcd(b,a-b)"

  2. Audio
    Observation

    The narrator says "For example, when kk equals 1, we get gcd a b equals gcd b a minus b, this is the famous subtraction-based algorithm"

Proof
Steps
  1. Expression
    gcd⁡(a,b)=gcd⁡(b,a−k⋅b)\gcd(a,b)=\gcd(b,a-k\cdot b)
    Explanation

    Start from the general recurrence formula given in the video.

    Justification

    Formula from Lecture section 1.

    Shown in the video
  2. Expression
    k=1k=1
    Explanation

    Let parameter kk take the value 1.

    Justification

    Lecture section 1.1 "Let k=1k=1".

    Shown in the video
  3. Expression
    gcd⁡(a,b)=gcd⁡(b,a−b)\gcd(a,b)=\gcd(b,a-b)
    Explanation

    Substitution yields the form of the subtraction-based algorithm.

    Justification

    Substituting k=1k=1 into a−kba-kb gives a−ba-b.

    Derived from the video
Conclusion

The subtraction-based algorithm gcd⁡(a,b)=gcd⁡(b,a−b)\gcd(a,b)=\gcd(b,a-b) is a special case of the general recurrence formula when k=1k=1.

Deriving Euclidean Algorithm by Substituting k=⌊a/ba/b into General Recurrence Formula

Clear evidence
Shown in the video
Evidence
  1. Formula
    Observation

    Lecture section 1 gcd⁡(a,b)=gcd⁡(b,a−k⋅b)\gcd(a,b)=\gcd(b,a-k\cdot b); Section 1.2 "Let k=⌊a/b⌋k=\lfloor a/b\rfloor, we get the Euclidean algorithm: gcd⁡(a,b)=gcd⁡(b,a mod b)\gcd(a,b)=\gcd(b,a\bmod b)"

  2. Audio
    Observation

    The narrator says "aa divided by bb, rounded down is the quotient of aa divided by bb", "Dividend minus quotient times divisor equals remainder"

  3. Animation
    Observation

    At seconds 99-107, formula a−k⋅ba-k\cdot b receives the handwritten annotation a−⌊a/b⌋ba-\lfloor a/b\rfloor b above it, then an arrow points to a mod ba\bmod b.

Uncertainties
  1. Video does not explicitly state the division prerequisite b≠0b\neq 0

Proof
Steps
  1. Expression
    gcd⁡(a,b)=gcd⁡(b,a−k⋅b)\gcd(a,b)=\gcd(b,a-k\cdot b)
    Explanation

    Start from the general recurrence formula given in the video.

    Justification

    Formula from Lecture section 1.

    Shown in the video
  2. Expression
    k=⌊a/b⌋k=\lfloor a/b\rfloor
    Explanation

    Let parameter kk take the floor of aa divided by bb, i.e., the quotient.

    Justification

    Lecture section 1.2 "Let k=⌊a/b⌋k=\lfloor a/b\rfloor"; Narrator calls it "the quotient of aa divided by bb".

    Shown in the video
  3. Expression
    a−k⋅b=a−⌊a/b⌋ba-k\cdot b=a-\lfloor a/b\rfloor b
    Explanation

    Substitute k=⌊a/b⌋k=\lfloor a/b\rfloor into the second argument.

    Justification

    Algebraic substitution.

    Derived from the video
  4. Expression
    a−⌊a/b⌋b=a mod ba-\lfloor a/b\rfloor b=a\bmod b
    Explanation

    Narrator explains that dividend minus quotient times divisor equals remainder.

    Justification

    Narrator states at seconds 107-112 "Dividend minus quotient times divisor equals remainder".

    Shown in the video
  5. Expression
    gcd⁡(a,b)=gcd⁡(b,a mod b)\gcd(a,b)=\gcd(b,a\bmod b)
    Explanation

    Obtain the form of the Euclidean algorithm.

    Justification

    Formula from Lecture section 1.2.

    Shown in the video
Conclusion

The Euclidean algorithm gcd⁡(a,b)=gcd⁡(b,a mod b)\gcd(a,b)=\gcd(b,a\bmod b) is a special case of the general recurrence formula when k=⌊a/b⌋k=\lfloor a/b\rfloor.

Worked examples · 2

Calculating gcd(24,504) using C++

Clear evidence
Shown in the video
Evidence
  1. Formula
    Observation

    The code has `const int a=24a = 24;`, `const int b=504b = 504;`, and `cout << gcd(a, b) << endl;`.

  2. Formula
    Observation

    The terminal outputs `24`.

  3. Audio
    Observation

    The instructor says "For example, let's take an example", "Let integer aa equal... 24", "Let integer bb equal... 504", "The result is 24."

Problem

Given two integers a=24a=24 and b=504b=504, find their greatest common divisor.

Given
  1. a=24a=24.

  2. b=504b=504.

  3. Use C++ code to call `gcd(a,b)`.

Goal

Calculate gcd⁡(24,504)\gcd(24,504) and output the result.

Steps
  1. Expression
    constinta=24;const int a = 24;
    Explanation

    Declare the first integer in the code.

    Justification

    The code line is visible on screen.

    Shown in the video
  2. Expression
    constintb=504;const int b = 504;
    Explanation

    Declare the second integer in the code.

    Justification

    The code line is visible on screen.

    Shown in the video
  3. Expression
    cout<<gcd(a,b)<<endl;cout << gcd(a, b) << endl;
    Explanation

    Call the `gcd` function and output the result.

    Justification

    The code line is visible on screen; the instructor explains using the built-in `gcd` function of C++.

    Shown in the video
  4. Expression
    2424
    Explanation

    The terminal displays the program output.

    Justification

    The terminal area on screen shows `24`.

    Shown in the video
Answer

gcd⁡(24,504)=24\gcd(24,504)=24.

Verification

The video verifies the result by running the C++ program and outputting 24 in the terminal.

Code Example: Enumerating k to Verify Invariance of gcd(24,504)

Clear evidence
Shown in the video
Evidence
  1. Formula
    Observation

    Code lines 6-15 fully visible: `const int a=24a = 24; const int b=504b = 504; const int c = gcd(a, b); for (int k=−1024k=-1024; k<=1024; ++k) { if (c != gcd(b, a−k∗ba - k * b)) { cout << k << endl; } } cout << "**********" << endl;`

  2. Diagram
    Observation

    Terminal at seconds 31-33 shows `$ g++ag++ a.cpp && ./a.out` followed by output `**********`

  3. Audio
    Observation

    The narrator says "You will find that this program only outputs a bunch of asterisks"

Uncertainties
  1. Video does not show the implementation of the `gcd` function, only the call result

Problem

Given a=24a=24, b=504b=504, let c=gcd⁡(a,b)c=\gcd(a,b), iterate integer kk from -1024 to 1024, check if there exists c≠gcd⁡(b,a−kb)c\neq\gcd(b,a-kb).

Given
  1. a=24a=24

  2. b=504b=504

  3. c=gcd⁡(a,b)c=\gcd(a,b)

  4. k∈[−1024,1024]k\in[-1024,1024]

Goal

Determine if there is any kk in the test range such that gcd⁡(a,b)≠gcd⁡(b,a−kb)\gcd(a,b)\neq\gcd(b,a-kb).

Steps
  1. Expression
    c=gcd⁡(24,504)c=\gcd(24,504)
    Explanation

    First calculate and store gcd⁡(a,b)\gcd(a,b).

    Justification

    Code line 8 `const int c = gcd(a, b);`.

    Shown in the video
  2. Expression
    for k=−1024 to 1024: if (c≠gcd⁡(504,24−k⋅504)) print k\text{for }k=-1024\text{ to }1024:\ \text{if }(c\neq\gcd(504,24-k\cdot 504))\ \text{print }k
    Explanation

    For each integer kk, check if the equality fails; if so, print kk.

    Justification

    Code lines 10-12.

    Shown in the video
  3. Expression
    print ∗∗∗∗∗∗∗∗∗∗\text{print }**********
    Explanation

    After the loop ends, print asterisk marker to indicate program completion.

    Justification

    Code line 15; Narrator says "To mark that my entire program has finished running, we finally output a bunch of asterisks".

    Shown in the video
  4. Expression
    terminal output: ∗∗∗∗∗∗∗∗∗∗\text{terminal output: }**********
    Explanation

    Actual terminal only displays asterisks, no kk values shown.

    Justification

    Terminal output at seconds 31-33.

    Shown in the video
Answer

No counterexamples were found in the test range k=−1024,−1023,…,1024k=-1024,-1023,\ldots,1024; the program only outputs `**********`.

Verification

Terminal output contains no kk values, only the loop end marker `**********`.

Visual events · 4

Document Displays Three GCD Formulas

Clear evidence
Shown in the video
Evidence
  1. Diagram
    Observation

    The screen shows a dark-background document page titled "Recurrence Formula for the Greatest Common Divisor of Two Numbers".

  2. Diagram
    Observation

    The page sequentially displays the core formula, 1.1 Subtraction Method, and 1.2 Euclidean Algorithm.

  3. Animation
    Observation

    The mouse moves near the formulas and selects parts of the text.

Objects
  1. Title "Recurrence Formula for the Greatest Common Divisor of Two Numbers".

  2. Formula gcd⁡(a,b)=gcd⁡(b,a−k⋅b)\gcd(a,b)=\gcd(b,a-k\cdot b).

  3. Subsection "1.1 Subtraction Method".

  4. Formula gcd⁡(a,b)=gcd⁡(b,a−b)\gcd(a,b)=\gcd(b,a-b).

  5. Subsection "1.2 Euclidean Algorithm".

  6. Formula gcd⁡(a,b)=gcd⁡(b,a mod b)\gcd(a,b)=\gcd(b,a\bmod b).

Changes
  1. The instructor explains from the general formula to the two special cases.

  2. The mouse points to text around the formulas.

Invariants
  1. All three formulas involve gcd⁡\gcd.

  2. The document structure remains a general formula plus two subsections.

Interpretation

The screen presents both the Subtraction Method and the Euclidean Algorithm as special cases of the same integer kk recurrence formula.

Code Editor Demonstrates GCD Call

Clear evidence
Shown in the video
Evidence
  1. Diagram
    Observation

    The screen switches to a code editor displaying a C++ program.

  2. Diagram
    Observation

    The code includes `#include <bits/stdc++.h>`, `using namespace std;`, `signed main()`, `const int a=24a = 24;`, `const int b=504b = 504;`, and `cout << gcd(a, b) << endl;`.

  3. Diagram
    Observation

    The terminal on the right shows compilation commands and output `24`.

  4. Animation
    Observation

    The instructor types code in the editor, runs the program, and continues adding `const int c = gcd(a, b);` and `for (int k=−1024k=-1024;k<=1024;++k)`.

Uncertainties
  1. A filename error prompt for `g++ aa.cpp` appeared once in the terminal, then changed to `g++ag++ a.cpp && ./a.out`; this detail does not affect the gcd example result.

Objects
  1. C++ source code editing area.

  2. Terminal output area.

  3. Variables `a`, `b`, `c` and loop variable `k`.

  4. Function call `gcd(a, b)`.

Changes
  1. Code changes from no output statement to calling `gcd(a,b)`.

  2. Terminal changes from empty or error state to outputting `24`.

  3. Later adds variable `c` and loop `for (int k=−1024k=-1024;k<=1024;++k)`.

Invariants
  1. Example values remain a=24a=24, b=504b=504.

  2. The core demonstration object is the calculation of `gcd(a,b)`.

Interpretation

The screen uses actual program execution to verify gcd⁡(24,504)=24\gcd(24,504)=24 and begins converting the abstract parameter kk into an enumerable integer loop.

Code Editing and Terminal Execution Process

Clear evidence
Shown in the video
Evidence
  1. Diagram
    Observation

    Left side VS Code editor shows C++ code; Right side terminal shows `$ g++ag++ a.cpp && ./a.out` and output `**********`

  2. Animation
    Observation

    From seconds 0-26, code is gradually completed: first `gcd(b, a−k∗ba-k*b)` appears, then wrapped in `if (c != ...)`, followed by adding `cout << k << endl;`, finally adding `cout << "**********" << endl;`

Objects
  1. VS Code editor

  2. Terminal window

  3. C++ code

  4. Compilation command

  5. Program output

Changes
  1. Code completes from syntactically incorrect `gcd(b, a−k∗ba-k*b)` to `if (c != gcd(b, a−k∗ba - k * b))`

  2. Loop body adds `cout << k << endl;`

  3. End of program adds `cout << "**********" << endl;`

  4. Terminal changes from old output `24` to recompiled `**********`

Invariants
  1. Variables a=24a=24, b=504b=504 remain unchanged

  2. Loop range k=−1024k=-1024 to 10241024 remains unchanged

Interpretation

The screen demonstrates no counterexamples in the test range by enumerating kk and only printing kk when the equality fails, with the terminal outputting only asterisks.

Lecture Page and Handwritten Derivation Annotations

Clear evidence
Shown in the video
Evidence
  1. Diagram
    Observation

    At second 48, switches to black-background white-text lecture, title "1 Recurrence Formula for GCD of Two Numbers", text "For any integer kk: gcd⁡(a,b)=gcd⁡(b,a−k⋅b)\gcd(a,b)=\gcd(b,a-k\cdot b)"

  2. Diagram
    Observation

    After second 69, sections 1.1 "Subtraction-based Algorithm" and 1.2 "Euclidean Algorithm" and their formulas are visible

  3. Animation
    Observation

    At seconds 99-107, formula a−k⋅ba-k\cdot b receives the pink handwritten annotation a−⌊a/b⌋ba-\lfloor a/b\rfloor b above it, with an arrow pointing to a mod ba\bmod b below.

Objects
  1. Lecture title

  2. General recurrence formula

  3. Subtraction-based algorithm section

  4. Euclidean algorithm section

  5. Pink handwritten annotation

  6. Arrow

Changes
  1. Page switches from code environment to lecture

  2. Narrator writes a−⌊a/b⌋ba-\lfloor a/b\rfloor b in pink pen on the second argument of the general formula

  3. Arrow connects this expression to a mod ba\bmod b

Invariants
  1. General formula gcd⁡(a,b)=gcd⁡(b,a−k⋅b)\gcd(a,b)=\gcd(b,a-k\cdot b) always appears as the parent formula

  2. Two special cases correspond to k=1k=1 and k=⌊a/b⌋k=\lfloor a/b\rfloor respectively

Interpretation

Visual annotations concretize a−kba-kb in the general recurrence as the remainder a mod ba\bmod b, illustrating that the Euclidean algorithm is a substitution special case of the general formula.

Misconceptions · 2

Misconception that Exam Environments Always Have Built-in GCD

Clear evidence
Shown in the video
Evidence
  1. Audio
    Observation

    The instructor says "I directly used the gcd function here because my C++ version is relatively new now, so it comes with the gcd function built-in."

  2. Audio
    Observation

    The instructor continues "But during exams, the C++ compiler version might not be this new, so you may need to implement the gcd function yourself during exams."

Misconception

Assuming all C++ exam environments can use the `gcd(a,b)` function just because it is called directly in the demo.

Clarification

The video explicitly reminds that the demo environment has a newer C++ version, but exam compilers might be older, requiring manual implementation of `gcd`.

Misconception that No Numeric Output Means Program Did Not Perform Checks

Clear evidence
Shown in the video
Evidence
  1. Audio
    Observation

    The narrator says "You will find that this program only outputs a bunch of asterisks, right? Understandable, that is to say, for any kk, gcd a b equals gcd b a minus kk times bb, always holds"

  2. Diagram
    Observation

    Terminal only shows `**********`, no kk displayed

Misconception

Seeing only asterisks in the terminal might lead one to mistakenly believe the program did not perform gcd comparisons.

Clarification

The video code is designed to output the corresponding kk only when `c != gcd(b, a−k∗ba - k * b)`; no kk output and only trailing asterisks indicates no counterexamples were found in the test range.

Concept relations · 7

Recurrence Formula for GCD of Two Numbers → Subtraction Method

Clear evidence
Shown in the video
Evidence
  1. Formula
    Observation

    The document first gives the core formula, then writes "Let k=1k=1, to get the Subtraction Method".

Special case
Explanation

The Subtraction Method is a special case of the core recurrence formula with k=1k=1.

Recurrence Formula for GCD of Two Numbers → Euclidean Algorithm

Clear evidence
Shown in the video
Evidence
  1. Formula
    Observation

    The document first gives the core formula, then writes "Let k=⌊a/b⌋k=\lfloor a/b\rfloor, to get the Euclidean Algorithm".

Special case
Explanation

The Euclidean Algorithm is a special case of the core recurrence formula with k=⌊a/b⌋k=\lfloor a/b\rfloor.

Recurrence Formula for GCD of Two Numbers → Calculating gcd(24,504) using C++

Clear evidence
Shown in the video
Evidence
  1. Formula
    Observation

    The code calls `gcd(a,b)` to calculate the example value.

  2. Audio
    Observation

    The instructor first explains the gcd recurrence formula, then gives an example calculating a=24,b=504a=24,b=504.

Uncertainties
  1. The video does not show the complete process of manually applying the recurrence formula, but uses the library function directly.

Application
Explanation

The example demonstrates greatest common divisor calculation with specific values, echoing the previous topic about gcd formulas.

Directly Calling gcd Function in C++ → Recurrence Formula for GCD of Two Numbers

Clear evidence
Shown in the video
Evidence
  1. Audio
    Observation

    The instructor says the demo environment can use `gcd` directly, but exams might require self-implementation.

Contrast
Explanation

The video contrasts "directly calling the existing `gcd` function" with "needing to understand and implement the gcd recurrence method manually".

Recurrence Formula for GCD of Two Numbers → Subtraction-based Algorithm as a Special Case of the Recurrence Formula

Clear evidence
Shown in the video
Evidence
  1. Formula
    Observation

    Lecture section 1 general formula gcd⁡(a,b)=gcd⁡(b,a−k⋅b)\gcd(a,b)=\gcd(b,a-k\cdot b); Section 1.1 "Let k=1k=1, we get the subtraction-based algorithm: gcd⁡(a,b)=gcd⁡(b,a−b)\gcd(a,b)=\gcd(b,a-b)"

Special case
Explanation

The subtraction-based algorithm is a special case of the recurrence formula when k=1k=1.

Recurrence Formula for GCD of Two Numbers → Euclidean Algorithm as a Special Case of the Recurrence Formula

Clear evidence
Shown in the video
Evidence
  1. Formula
    Observation

    Lecture section 1 general formula gcd⁡(a,b)=gcd⁡(b,a−k⋅b)\gcd(a,b)=\gcd(b,a-k\cdot b); Section 1.2 "Let k=⌊a/b⌋k=\lfloor a/b\rfloor, we get the Euclidean algorithm: gcd⁡(a,b)=gcd⁡(b,a mod b)\gcd(a,b)=\gcd(b,a\bmod b)"

Special case
Explanation

The Euclidean algorithm is a special case of the recurrence formula when k=⌊a/b⌋k=\lfloor a/b\rfloor.

Code Example: Enumerating k to Verify Invariance of gcd(24,504) → GCD Remains Invariant for Any Integer k

Clear evidence
Shown in the video
Evidence
  1. Diagram
    Observation

    Code enumerates kk and checks `c != gcd(b, a−k∗ba - k * b)`; Terminal only outputs `**********`

  2. Audio
    Observation

    Narrator infers from "only output a bunch of asterisks" that "For any kk... always holds"

Uncertainties
  1. Code only verifies finite range k∈[−1024,1024]k\in[-1024,1024], narrator verbally generalizes to any integer kk

Application
Explanation

The code example is used to support the proposition of gcd invariance for any integer kk.

Find an answer · 9

What is the recurrence formula for the greatest common divisor of two numbers?

Clear evidence
Shown in the video
Evidence
  1. Formula
    Observation

    The document title and core formula are visible.

Knowledge points
  1. Recurrence Formula for GCD of Two Numbers

How is the Subtraction Method derived from the gcd recurrence formula?

Clear evidence
Shown in the video
Evidence
  1. Formula
    Observation

    The document writes "Let k=1k=1, to get the Subtraction Method".

Knowledge points
  1. Recurrence Formula for GCD of Two Numbers
  2. Subtraction Method
  3. Deriving Subtraction Method from Core Formula

What is the relationship between the Euclidean Algorithm and the gcd recurrence formula?

Clear evidence
Shown in the video
Evidence
  1. Formula
    Observation

    The document writes "Let k=⌊a/b⌋k=\lfloor a/b\rfloor, to get the Euclidean Algorithm".

Knowledge points
  1. Recurrence Formula for GCD of Two Numbers
  2. Euclidean Algorithm
  3. Deriving Euclidean Algorithm from Core Formula

What is gcd(24,504)?

Clear evidence
Shown in the video
Evidence
  1. Formula
    Observation

    The code sets `a=24a=24`, `b=504b=504`, and the terminal outputs `24`.

Knowledge points
  1. Calculating gcd(24,504) using C++
  2. Value of gcd(24,504) in the Example
  3. Numerical Verification gcd(24,504)=24

Why can the gcd function be called directly in the video, but might need to be written manually in exams?

Clear evidence
Shown in the video
Evidence
  1. Audio
    Observation

    The instructor explains that `gcd` can be used directly because the C++ version is new, and warns that exams might require self-implementation.

Knowledge points
  1. Directly Calling gcd Function in C++
  2. Misconception that Exam Environments Always Have Built-in GCD

What is the recurrence formula for the greatest common divisor of two numbers?

Clear evidence
Shown in the video
Evidence
  1. Formula
    Observation

    Lecture section 1 "For any integer kk: gcd⁡(a,b)=gcd⁡(b,a−k⋅b)\gcd(a,b)=\gcd(b,a-k\cdot b)"

Knowledge points
  1. Recurrence Formula for GCD of Two Numbers

Why does the program outputting only asterisks prove the gcd equality holds?

Clear evidence
Shown in the video
Evidence
  1. Diagram
    Observation

    Terminal only outputs `**********`

  2. Audio
    Observation

    Narrator explains "only output a bunch of asterisks" means no kk causes the equality to fail

Knowledge points
  1. Code Example: Enumerating k to Verify Invariance of gcd(24,504)
  2. GCD Remains Invariant for Any Integer k
  3. Misconception that No Numeric Output Means Program Did Not Perform Checks

How is the subtraction-based algorithm derived from the gcd recurrence formula?

Clear evidence
Shown in the video
Evidence
  1. Formula
    Observation

    Lecture section 1.1 "Let k=1k=1, we get the subtraction-based algorithm: gcd⁡(a,b)=gcd⁡(b,a−b)\gcd(a,b)=\gcd(b,a-b)"

Knowledge points
  1. Subtraction-based Algorithm as a Special Case of the Recurrence Formula
  2. Deriving Subtraction-based Algorithm by Substituting k=1k=1 into General Recurrence Formula

Why does letting k=⌊a/ba/b⌋ yield the Euclidean algorithm?

Clear evidence
Shown in the video
Evidence
  1. Formula
    Observation

    Lecture section 1.2 "Let k=⌊a/b⌋k=\lfloor a/b\rfloor, we get the Euclidean algorithm: gcd⁡(a,b)=gcd⁡(b,a mod b)\gcd(a,b)=\gcd(b,a\bmod b)"

  2. Animation
    Observation

    Handwritten annotation a−⌊a/b⌋ba-\lfloor a/b\rfloor b points to a mod ba\bmod b

Knowledge points
  1. Euclidean Algorithm as a Special Case of the Recurrence Formula
  2. Deriving Euclidean Algorithm by Substituting k=⌊a/ba/b into General Recurrence Formula
Coverage and review notes

Covered · Document view and narration cover the core gcd recurrence formula and its two special cases.

Covered · Code editor and terminal demonstrate the numerical result of `gcd(24,504)` and discuss limitations of using C++ built-in `gcd`.

Covered · Code writing, compilation execution, and terminal output verify gcd recurrence invariance.

Covered · Lecture presents the recurrence formula for the greatest common divisor of two numbers.

Covered · Lecture presents the subtraction-based algorithm as a special case for k=1k=1.

Covered · Lecture and handwritten annotations present the Euclidean algorithm as a special case for k=⌊a/ba/b⌋.

Explore the knowledge in this video

Open video knowledge graph →

  • Greatest common divisor ApplicationAt 0:38
    Why this connection?

    From 38 to 175 seconds, the C++ example computes gcd(24,504)=24 and tests gcd(504,24−k∗50424-k*504) for integer k from -1024 through 1024. The terminal reports no counterexample in that finite range; the public review explicitly says this finite test is not a universal proof.

  • Euclidean algorithm ExplanationAt 2:55
    Why this connection?

    From 175 to 254 seconds, the source states gcd(a,b)=gcd(b,a-kb), sets k=1k=1 for the subtraction method, then sets k=floor(a/ba/b) and visually connects a-floor(a/ba/b)b to a mod b, yielding gcd(a,b)=gcd(b,a mod b). The review records the missing b!=0 and remainder-convention boundary, so this is explanation rather than proof.