[Verse 1]
Ancient Greek mathematician had a vision so precise
Eratosthenes conceived a method, rolling algorithmic dice
Start with integers from two, extend them to your limit
Cross out multiples in sequence, let the pattern exhibit
Take the smallest unmarked number, circle it with pride
Every multiple gets eliminated, nowhere left to hide
[Chorus]
Sieve it, sieve it, cross the composites out
Prime numbers surface when you filter without doubt
Square root boundary, that's your stopping ground
Sieve of Eratosthenes, primes are what you've found
[Verse 2]
Begin with two, the only even prime that makes the cut
Mark four, six, eight, and every even after, case is shut
Move to three, the next survivor in your unmarked crew
Nine, fifteen, twenty-one, their composite fate is due
Skip the crossed-out casualties, find five standing strong
Strike twenty-five and thirty-five, the pattern moves along
[Chorus]
Sieve it, sieve it, cross the composites out
Prime numbers surface when you filter without doubt
Square root boundary, that's your stopping ground
Sieve of Eratosthenes, primes are what you've found
[Bridge]
Time complexity linear when you count the operations
Space complexity matches range in memory allocations
Optimizations possible with bit arrays so tight
Wheel factorization techniques make the algorithm bright
[Verse 3]
Why stop at square root, students always wonder why
Larger factors must have partners smaller than that high
If n equals a times b, and both exceed the root
One factor stays below it, mathematical absolute
The sieve reveals the treasures, primes in perfect line
Composite numbers vanished, leaving gems that shine
[Outro]
From ancient Alexandria to modern coding streams
The sieve still filters numbers, fulfilling Euclid's dreams