Chuyển tới nội dung chính
Z

Number Theory

Primes, GCD & sequences — the math behind algorithms

Number theory underpins cryptography, hashing and countless coding-interview problems. A little of it goes a long way.

Primes & factorization

The Sieve of Eratosthenes finds all primes up to n by repeatedly crossing out multiples, running in about O(n log log n) — far faster than testing each number alone. Prime factorization breaks a number into its prime building blocks, the foundation of RSA-style cryptography and of computing least common multiples.

The Euclidean algorithm

The Euclidean algorithm computes the greatest common divisor of two numbers in logarithmic time using nothing but repeated remainder: gcd(a, b) = gcd(b, a mod b). It is one of the oldest algorithms still in everyday use, from simplifying fractions to modular inverses.

Sequences & conjectures

Famous sequences make great visual playgrounds. The Collatz conjecture — repeatedly halve even numbers and triple-and-add-one odd ones — always seems to reach 1, yet no one has proved it must. Watch the orbit bounce toward 1 below.

Try it interactively

Prefer a focused tool?

Câu hỏi thường gặp

Giả thuyết Collatz là gì?

Bắt đầu với một số nguyên dương bất kỳ. Nếu số đó chẵn, chia cho 2; nếu lẻ, tính 3n+1. Giả thuyết cho rằng quá trình này luôn cuối cùng sẽ về 1, bất kể số bắt đầu là gì.

Giả thuyết Collatz đã được chứng minh chưa?

Chưa. Giả thuyết này vẫn chưa được chứng minh dù đã có rất nhiều nỗ lực, mặc dù nó đã được kiểm chứng bằng máy tính cho mọi giá trị bắt đầu lên tới những con số lớn đến mức khó tưởng tượng.

Tại sao số 27 lại thú vị?

Bắt đầu từ 27, dãy số mất 111 bước và leo cao tới tận 9232 trước khi cuối cùng giảm xuống 1 — một hành trình bất ngờ kịch tính cho một số khởi đầu nhỏ như vậy.

Dãy số này được gọi là gì?

Dãy các giá trị này được gọi là quỹ đạo Collatz (hay quỹ đạo 3n+1), và số bước để về 1 được gọi là tổng thời gian dừng (total stopping time) của nó.