Same answer. Math for DSA.
Tap to start →
To check if n is prime, test divisors only up to its square root.
Cross out multiples of each prime. Everything left is prime.
gcd(a, b) = gcd(b, a % b), until b is 0.
Answers too big? Take % 1,000,000,007 after every step.
In Java, −7 % 3 is −1, not 2. Add the divisor and take % again.
Tap an answer. The full video explains why.
Free DSA in Java course. Subscribe to Compiled Canvas on YouTube.