Intermediate Number Theory Problems for Coding Interviews
58 intermediate Number Theory problems from real coding interviews, each with test cases you can run online. By difficulty they split into 0 basic, 58 intermediate and 0 advanced. The companies that ask them most often are Amazon, Google, Meta, Microsoft.
Solve a few problems of each level, name the pattern after each one and revisit the ones that needed a hint a week later. Practise stating the time and space complexity and the edge cases before you code.
Coding problems
- Count Primes (Intermediate)
- Greatest Common Divisor of Strings (Intermediate)
- Prime Factorization (Intermediate)
- Prime Factorization Queries (Intermediate)
- Count Divisible Numbers in Range (Intermediate)
- Ugly Number II (Intermediate)
- Super Ugly Number (Intermediate)
- Smallest Divisor Given a Threshold (Intermediate)
- Divide Two Integers (Intermediate)
- Count Simplified Fractions (Intermediate)
- Sum of Four Divisors (Intermediate)
- Closest Divisors (Intermediate)
- Smallest Value After Prime Factor Sums (Intermediate)
- Distinct Prime Factors of Product (Intermediate)
- Closest Prime Numbers in Range (Intermediate)
- Count Subarrays With GCD Equal to K (Intermediate)
- Count Subarrays With LCM Equal to K (Intermediate)
- Smallest Number With Exactly N Divisors (Intermediate)
- Sum of Largest Prime Factors (Intermediate)
- Count Numbers Coprime to N in a Range (Intermediate)
- Multiplicative Order Modulo N (Intermediate)
- Modular Inverse Queries (Intermediate)
- Divisor Count Queries (Intermediate)
- Maximum GCD Over Pairs (Intermediate)
- Count Numbers Divisible by Any Given Prime (Intermediate)
- Ordered Pairs With Given LCM (Intermediate)
- Amicable Numbers Sum Below N (Intermediate)
- Goldbach Partition Count (Intermediate)
- N-th Prime Number (Intermediate)
- Emirp Count Below N (Intermediate)
- Circular Primes Count Below N (Intermediate)
- Sophie Germain Primes Below N (Intermediate)
- Semiprimes Up To N (Intermediate)
- Integers With Exactly K Distinct Prime Factors (Intermediate)
- Totient Summatory Function (Intermediate)
- Next Prime After N (Intermediate)
- Batch Primality Test (Intermediate)
- Sum of Smallest Prime Factors (Intermediate)
- Smallest Solution of Two Congruences (Intermediate)
- Legendre Symbol (Intermediate)
- Roots of Unity Count Modulo Prime (Intermediate)
- Sum of Modular Inverses (Intermediate)
- Count K-th Power Residues Modulo Prime (Intermediate)
- Bezout Coefficient Modular Form (Intermediate)
- Inverse of 2x2 Matrix Modulo M (Intermediate)
- Visible Lattice Points From Origin (Intermediate)
- Highly Divisible Triangular Number (Intermediate)
- Consecutive Integers With Equal Divisor Count (Intermediate)
- Sum of K-th Powers of Divisors (Intermediate)
- Dedekind Psi Function (Intermediate)
- Sum of Unitary Divisors (Intermediate)
- Aliquot Sequence Length (Intermediate)
- Number of Cube-Free Divisors (Intermediate)
- Sum of Odd Divisors (Intermediate)
- Range GCD Queries (Intermediate)
- Smith Number Check (Intermediate)
- Integers With Exactly Three Divisors (Intermediate)
- Choose Count Modulo Prime (Intermediate)
Related
Frequently asked questions
How do I get good at number theory problems?
Practise by level, name the pattern after you solve each problem and review the ones you needed hints for. The list is ordered so you can start with the basic ones.
Can I run number theory problems online here?
Yes. Each problem opens in an editor that runs your code against test cases in Java, Python, C++, Go, JavaScript and more.