Number theory coding challenges

Practise number theory with 41 coding challenges, from easy to hard. Every challenge runs in your browser with instant tests, an AI review of your code and community solutions to compare.

Easy · 12 Medium · 26 Hard · 3

Skills you'll practise: Sieve of EratosthenesBig number arithmeticPrimality testingModular arithmeticPrime factorizationSquare root boundCycle detectionDigit manipulationDivisor pairsMemoizationPair enumerationTrial division
  • Python · C++ · C#
  • Automated tests
  • AI code review
  • Community solutions
341
Challenges
245
Solutions shared
9
Languages

All challenges

Search by name or topic, or filter by difficulty.

41 challenges
Medium

Sum of Primes Below a Limit

Add all primes strictly below a limit.

You'll learn Sieve of EratosthenesSumming primes
Number-theorySieve
Medium

Largest Prime Factor

Find the largest prime that divides a positive integer.

You'll learn Prime factorizationTrial division
AlgorithmsNumber-theory
Medium

List Primes With a Sieve

Find primes up to a limit by marking composite multiples.

You'll learn Sieve of EratosthenesBoolean arrays
Number-theorySieve
Medium

Find Right-Triangle Triples

List all integer right triangles with a specified perimeter.

You'll learn EnumerationAvoiding duplicates
GeometryNumber-theory
Medium

Right-Triangle Product

Find the largest side product of an integer right triangle with a given perimeter.

You'll learn Right trianglesSearch pruning
GeometryNumber-theory
Easy

Classify a Number by Its Divisors

Classify a positive integer as perfect, abundant, or deficient.

You'll learn DivisorsClassification
BeginnerNumber-theory
Easy

Count Primes in a Range

Count how many prime numbers lie between two bounds, both included.

You'll learn Sieve of EratosthenesRange counting
BeginnerCS1High schoolLoopsNumber-theoryNumbersPrimesmath
No solutions yet
Medium

Largest Product in a Grid

Find the largest product of k numbers in a straight line in a grid.

You'll learn 2D grid traversalDirection vectors
Competitive-programmingDynamic-programmingGridsIntermediateMatricesNumber-theoryProject Euler stylemath
No solutions yet
Medium

Goldbach Partition

Write an even number as the sum of two primes, using the smallest possible first prime.

You'll learn Primality testingSearching from the smallest candidate
CS1Dynamic-programmingHigh schoolIntermediateLoopsNumber-theoryNumbersPrimesmath
No solutions yet
Hard

Longest Recurring Cycle

Find the d up to a limit whose fraction 1/d has the longest repeating decimal block.

You'll learn Long divisionCycle detection
AdvancedCompetitive-programmingDFSNumber-theoryProject Euler stylemath
No solutions yet
Medium

Maximum Path Sum in a Triangle

Find the largest sum on a path from the top of a number triangle to its bottom row.

You'll learn Dynamic programmingBottom-up computation
Competitive-programmingDynamic-programmingIntermediateNumber-theoryProject Euler styleTreesmath
No solutions yet
Medium

Prime Factorization

Break a number into its prime factors, listed from smallest to largest with repetition.

You'll learn Trial divisionSquare root bound
CS1High schoolIntermediateLoopsNumber-theoryNumbersPrimesmath
No solutions yet
Medium

Longest Collatz Chain

Find the starting number up to a limit whose Collatz chain is longest.

You'll learn MemoizationSimulation
Competitive-programmingIntermediateNumber-theoryProject Euler stylemath
No solutions yet
Easy

First Fibonacci With N Digits

Find the position of the first Fibonacci number that has n digits.

You'll learn Big number arithmeticSequences
BeginnerBig integersCompetitive-programmingNumber-theoryProject Euler stylemath
No solutions yet
Easy

Factorial Digit Sum

Add up the decimal digits of n factorial.

You'll learn Big number arithmeticDigit manipulation
BeginnerBig integersCompetitive-programmingNumber-theoryProject Euler stylemath
No solutions yet
Hard

Digit Factorial Chains

Count starting numbers whose digit factorial chain has exactly a given number of distinct terms.

You'll learn Cycle detectionMemoization
AdvancedCompetitive-programmingNumber-theoryProject Euler stylemath
No solutions yet
Easy

Self Powers Tail

Find the last k digits of 1^1 + 2^2 + ... + n^n.

You'll learn Modular arithmeticFast exponentiation
BeginnerBig integersCompetitive-programmingNumber-theoryProject Euler stylemath
No solutions yet
Easy

Smallest Multiple

Find the smallest positive number that every integer in a range divides evenly.

You'll learn Greatest common divisorLeast common multiple
BeginnerCompetitive-programmingConditionsFinanceFunctionsNumber-theoryProject Euler stylemath
No solutions yet