Saltar al contenido principal
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?

Preguntas frecuentes

¿Qué es la conjetura de Collatz?

Empieza con cualquier número entero positivo. Si es par, divídelo entre 2; si es impar, calcula 3n+1. La conjetura afirma que este proceso siempre termina llegando a 1, sin importar cuál sea el número inicial.

¿Se ha demostrado la conjetura de Collatz?

No. La conjetura sigue sin demostrarse pese a los numerosos esfuerzos realizados, aunque se ha verificado por ordenador para todos los valores iniciales hasta cifras extremadamente grandes.

¿Por qué es interesante el número 27?

Partiendo de 27, la secuencia tarda 111 pasos y llega a alcanzar hasta 9232 antes de finalmente bajar a 1 — un recorrido sorprendentemente dramático para un número inicial tan pequeño.

¿Cómo se llama esta secuencia?

A esta serie de valores se le llama trayectoria de Collatz (o trayectoria 3n+1), y el número de pasos necesarios para llegar a 1 se conoce como su tiempo total de parada (total stopping time).