COMPILED CANVAS
DSA IN JAVA

A billion steps, or 31,623?

Same answer. Math for DSA.

Tap to start →

PRIMES

Stop at √n

√1,000,000,000 ≈ 31,623

To check if n is prime, test divisors only up to its square root.

1 of 4 · keep tapping →
SIEVE

All primes at once

23456789

Cross out multiples of each prime. Everything left is prime.

2 of 4 · keep tapping →
GCD

Euclid's trick

int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); }

gcd(a, b) = gcd(b, a % b), until b is 0.

3 of 4 · keep tapping →
MODULO

Keep numbers small

% (10⁹ + 7)

Answers too big? Take % 1,000,000,007 after every step.

4 of 4 · keep tapping →
⚠ MOST PEOPLE MISS THIS

The mistake

In Java, −7 % 3 is −1, not 2. Add the divisor and take % again.

QUICK QUIZ

Can you get it?

Tap an answer. The full video explains why.

📸 SCREENSHOT THIS

Cheat sheet

  • Prime check: up to √n
  • Sieve: cross out multiples
  • gcd(a,b) = gcd(b, a%b)
  • Mod after every step
  • Negative %: add and % again
COMPILED CANVAS

Want the full lesson?

▶ Watch the full videoPractice + free notes

Free DSA in Java course. Subscribe to Compiled Canvas on YouTube.

Watch the full video