3. Basic Math
Primes, GCD, modulo, digits and the Sieve of Eratosthenes.
Your progress0 of 13
7easy
5medium
1hard
Understand the topic
A lot of coding questions hide simple maths: pulling digits out with % 10 and / 10, the GCD with Euclid's rule, primes with the Sieve, fast powers by squaring, and keeping numbers small with modulo 1e9+7.
Watch for overflow in every problem here. If a value can pass about 2.1 billion, use long, and check the limit before you multiply, not after.
| # | Problem | Pattern | Level | ||
|---|---|---|---|---|---|
| 1 | Palindrome Number #9 | Digit reversal | Easy | LeetCode ↗ | |
| 2 | Subtract the Product and Sum of Digits of an Integer #1281 | Digit extraction | Easy | LeetCode ↗ | |
| 3 | Count the Digits That Divide a Number #2520 | Digit extraction + modulo | Easy | LeetCode ↗ | |
| 4 | Add Digits #258 | Digital root | Easy | LeetCode ↗ | |
| 5 | Find Greatest Common Divisor of Array #1979 | Euclid's GCD | Easy | LeetCode ↗ | |
| 6 | Greatest Common Divisor of Strings #1071 | GCD on lengths | Easy | LeetCode ↗ | |
| 7 | Ugly Number #263 | Prime factors | Easy | LeetCode ↗ | |
| 8 | Reverse Integer #7 | Overflow checks | Medium | LeetCode ↗ | |
| 9 | Count Primes #204 | Sieve of Eratosthenes | Medium | LeetCode ↗ | |
| 10 | Pow(x, n) #50 | Fast exponentiation | Medium | LeetCode ↗ | |
| 11 | Factorial Trailing Zeroes #172 | Counting factors | Medium | LeetCode ↗ | |
| 12 | Count Good Numbers #1922 | Modular exponentiation | Medium | LeetCode ↗ | |
| 13 | Consecutive Numbers Sum #829 | Number theory | Hard | LeetCode ↗ |
Nothing matches that filter.
Work top to bottom — each list goes from easy to hard. Try a problem for at least 15 minutes before opening a hint. Ticks are saved in your browser.
