1.1.8 · HinglishArithmetic & Number Systems

Prime numbers — Sieve of Eratosthenes, primality testing

1,558 words7 min readRead in English

1.1.8 · Maths › Arithmetic & Number Systems


1. Prime kya hota hai? (WHAT)


2. Trial-division primality test — scratch se derive karo (HOW + WHY)

Goal: decide karo ki prime hai ya nahi.

Naive tarika: se tak har test karo. Agar koi ko divide na kare, toh prime hai. Sahi hai lekin slow hai.

Key optimisation — kyun?

Maano composite hai, toh jahan .

Toh test yeh ban jaata hai:

Cost se gir ke ho jaati hai.


3. Sieve of Eratosthenes — first principles se banao

Idea: Numbers ko ek-ek karke test karne ki jagah, har prime ke saare multiples cross out karo. Jo bachta hai woh prime hai.

Figure — Prime numbers — Sieve of Eratosthenes, primality testing

4. Common mistakes (Steel-man → Fix)


5. Active recall

Recall Pehle khud try karo, phir reveal karo
  • Trial-division bound kyun hai?
  • Sieve se crossing kyun shuru karta hai?
  • Ek aisa composite do jo "sirf 2,3,5 check karo" se bachke nikal jaaye.

Answers: pair ka chhota factor hota hai; multiples pehle hi chhote primes se cross ho gaye hain; ya .

Recall Feynman: ek 12-saal ke bachche ko samjhao

Socho numbers ek line mein khade hain. Prime woh baccha hai jo sirf blocks ki seedhi single line bana sakta hai — kabhi ek neat rectangle nahi. Sieve ek game hai: 2 apne saare "doston" (4, 6, 8…) ko baith jaane kehta hai. Phir 3 wahi karta hai, phir 5. Akhir mein jo bhi khada rehta hai woh kabhi baith nahi sakta — woh primes hain! Aur tumhe sirf pehle kuch callers chahiye, kyunki bade rectangles pehle hi chhote waalon ne gira diye hote hain.


6. The 80/20 core

  • Prime = exactly do divisors. 1 na prime na composite.
  • Primality: tak divisors check karo.
  • Sieve: har ke multiples se cross karo; par ruko; survivors prime hain.

Define a prime number
Ek natural number jiske sirf positive divisors 1 aur hain (exactly do distinct divisors).
Is 1 prime, composite, or neither?
Neither — uska sirf ek divisor hai, aur isko allow karne se unique factorisation toot jaata hai.
Why need we only trial-divide up to ?
Agar jahan , toh ; se upar ka divisor ek partner se neeche force karta hai.
In the Sieve, from which multiple do we start crossing out ?
se — chhote multiples pehle hi chhote primes se cross ho chuke hain.
In the Sieve up to , when do we stop sieving?
Jab ho (yaani ); baaki numbers automatically prime hain.
Give a composite that survives "test only 2,3,5".
(ya , ).
List all primes below 30.
2,3,5,7,11,13,17,19,23,29.
Time complexity of trial division per number?
.
State the Fundamental Theorem of Arithmetic.
Har integer uniquely primes mein factor hota hai (order ko chhodke).
Is 91 prime?
Nahi, .

Connections

Concept Map

only divisors

has divisor d

excluded to keep unique

building blocks of

factors as

smaller factor bound

justifies

cost

test one number

cross out multiples of

start crossing at

smaller multiples already gone

survivors are

Prime p greater than 1

1 and p itself

Composite n

d with 1 less than d less than n

Number 1

Fundamental Theorem of Arithmetic

n = a times b

a less than or equal sqrt n

Trial-division test

O of sqrt n

Sieve of Eratosthenes

p squared