Talentd
FleetCode
Make and follow sheets.Sign in

Number Theory Problems (98)

Problems tagged with Number Theory. Start with the easy ones, then move to medium and hard.

13 Easy45 Medium40 Hard

Learn these first

1
Math

Number Theory is built on mathematical fundamentals such as divisibility, primes, and modular arithmetic. Strong math intuition helps you derive formulas and simplify algorithmic problems.

2
Hash Table

Hash tables are often used to store remainders, frequency counts, or modular results when solving number theory problems efficiently.

3
Prefix Sum

Prefix sums help solve range-based divisibility or modular arithmetic problems by allowing constant-time queries after preprocessing.

4
Combinatorics

Counting techniques, permutations, and combinations frequently appear alongside number theory when solving problems involving divisibility constraints or modular counting.

5
Bit Manipulation

Many number theory optimizations rely on bitwise tricks, such as fast exponentiation and power-of-two operations. Understanding bit manipulation helps improve performance in numeric algorithms.

TitleSolutionAcceptDifficultyTopics
Solution27.5%Hard
Hash Table, Math +3· 1 company
Solution35.7%Medium
Array, Greedy +2· 4 companies
Solution45.5%Medium
Array, Counting +5· 1 company
Solution59.3%Medium
Array, Math +1· 1 company
Solution58.4%Hard
Array, Binary Search +6· 1 company
Solution41.0%Medium
Array, Math +1· 1 company
Solution37.9%Medium
Hash Table, Math +3· 1 company
–19.0%Hard
Array, Math +2· 1 company
Solution25.5%Hard
Array, Enumeration +2· 1 company
–23.7%Medium
Array, Math +4· 1 company
–20.4%Hard
Array, Binary Search +4· 1 company
Solution89.8%Easy
Math, Number Theory· 3 companies
Solution40.2%Medium
Backtracking, Math +1· 2 companies
–31.5%Hard
Array, Binary Indexed Tree +2· 2 companies
–41.3%Hard
Array, Counting +5· 3 companies
Solution39.0%Medium
Array, Math +1· 2 companies
Solution35.6%Hard
Array, Dynamic Programming +3· 2 companies
Solution75.1%Medium
Array, Math +3· 1 company
Solution19.9%Hard
Array, Math +2· 2 companies
–32.2%Medium
Array, Greedy +3· 1 company
–27.5%Hard
Array, Combinatorics +4· 2 companies
3984. Divisible GameVideo
–42.3%Medium
Showing 51–98 of 98

More about Number Theory

Number Theory is a fundamental branch of mathematics focused on the properties and relationships of integers. In data structures and algorithms (DSA), number theory techniques are widely used to solve problems involving divisibility, prime numbers, modular arithmetic, greatest common divisors (GCD), and combinatorial counting. Many competitive programming and coding interview problems rely on these concepts because they allow efficient solutions to problems that would otherwise require brute force.

In technical interviews, number theory questions test your ability to recognize mathematical patterns and apply optimized formulas. Instead of iterating through every possible value, strong candidates use techniques like modular arithmetic, fast exponentiation, the Sieve of Eratosthenes, and Euclid’s algorithm to reduce time complexity dramatically. These concepts often appear in companies that value algorithmic thinking, including FAANG-level interviews and competitive programming contests.

Number theory also overlaps with several other DSA topics. Many problems combine mathematical insights with Math fundamentals, bit-level optimizations from Bit Manipulation, or counting strategies from Combinatorics. In some cases, you may use Hash Table techniques to store remainders or intermediate results, or leverage Prefix Sum patterns when working with divisibility conditions across ranges.

Common number theory patterns include:

  • Computing GCD/LCM using Euclid’s algorithm
  • Prime generation with sieve techniques
  • Modular arithmetic and modular inverses
  • Fast exponentiation (binary exponentiation)
  • Divisor counting and factorization

The best way to master these ideas is through consistent practice. FleetCode provides 63 carefully selected Number Theory problems that progress from foundational concepts to advanced interview-level challenges. By practicing these problems, you’ll learn how to recognize mathematical patterns quickly and apply efficient algorithms during coding interviews.

Number Theory: common questions

Is Number Theory important for FAANG interviews?

Number Theory appears less frequently than arrays or graphs, but it still shows up in algorithm-heavy interviews and competitive programming rounds. FAANG-style problems often involve modular arithmetic, fast exponentiation, or mathematical optimizations. Knowing the core patterns can give you a strong advantage.

What is the best way to learn Number Theory for DSA?

Start by learning the core concepts such as GCD, prime numbers, modular arithmetic, and factorization. Then practice progressively harder problems while recognizing patterns like binary exponentiation or sieve methods. Consistent problem solving is the fastest way to internalize these techniques.

What are common Number Theory patterns in coding problems?

Common patterns include Euclid’s algorithm for GCD, Sieve of Eratosthenes for prime generation, modular arithmetic for large-number computations, binary exponentiation for fast power calculation, and divisor enumeration. These techniques help reduce brute-force solutions to efficient logarithmic or linear algorithms.

Do competitive programming contests use Number Theory a lot?

Yes. Competitive programming platforms frequently include number theory problems because they reward mathematical insight and efficient algorithms. Topics like modular arithmetic, primes, and combinatorial counting are especially common in contest problems.

What are the best Number Theory problems for coding interviews?

The best Number Theory interview problems focus on GCD/LCM, modular arithmetic, prime sieves, fast exponentiation, and divisor counting. These patterns appear frequently in competitive programming and technical interviews.

How many Number Theory problems should I solve to master the topic?

This range typically covers prime generation, modular arithmetic, factorization, and mathematical optimizations.