Editor

Python math exercises

Number problems in Python, from digits and primes to counting, each checked by tests in your browser.

Beginner

  1. 29. Digital RootSqueeze a huge number down to a single digit30 XP5 min
  2. 210. Armstrong Number153 has a secret hidden in its own digits30 XP5 min
  3. 218. Greatest Common DivisorThe biggest square tile that covers a floor with no cutting30 XP5 min
  4. 224. Reverse an IntegerRead a number from right to left, minus sign and all30 XP5 min
  5. 241. Perfect NumberSix is perfect, and so is 28: is your number one of them?35 XP7 min
  6. 246. Triangle TypeThree sticks: what kind of triangle do they make, if any?35 XP6 min

Intermediate

  1. 72. Primes Up to NEvery prime number, all the way up to a limit65 XP12 min
  2. 87. Trailing Zeros of a FactorialHow many zeros sit at the end of a gigantic number?70 XP10 min
  3. 88. Convert Between BasesTranslate a number from one counting system to another75 XP14 min
  4. 272. Least Common Multiple of a ListEvery bus left the depot at six. When do they all leave together again?60 XP10 min
  5. 280. Count the DivisorsIn how many ways can the chairs be set out in neat rows?65 XP10 min
  6. 286. Prime FactorsBreak a number down into the primes it is built from65 XP12 min
  7. 291. The Nth PrimeWhich prime stands ten-thousandth in line?65 XP12 min
  8. 315. Catalan NumbersHow many ways can brackets pair up without tangling?75 XP15 min
  9. 323. Right Triangles With Whole SidesThe 3-4-5 triangle has many cousins: find them all75 XP15 min

Advanced

  1. 154. Fraction to Recurring DecimalWrite any fraction as a decimal, even the ones that never end140 XP30 min
  2. 349. Egyptian FractionsWrite any fraction the way the scribes of ancient Egypt did120 XP20 min
  3. 359. Next Bigger NumberShuffle the digits to get the very next number up125 XP20 min
  4. 364. Decimal to FractionTurn any decimal, even one that repeats forever, back into a fraction130 XP25 min
  5. 382. Binomial Coefficients Modulo a PrimeAnswer thousands of how-many-ways questions in the blink of an eye140 XP25 min
  6. 385. Fibonacci of a Huge IndexJump straight to the billion-billionth Fibonacci number140 XP25 min
  7. 406. Dice Sum ProbabilityRoll a fistful of dice: how likely is that exact total?150 XP30 min
  8. 415. Primes in a WindowHow many primes live between two numbers near a billion?150 XP30 min
  9. 426. The Chinese Remainder PuzzleCounted in threes, fives and sevens: how many coins are in the pile?160 XP30 min

Expert

  1. 183. Digits in Page NumbersA book with a billion billion pages: how often is one digit printed?230 XP45 min
  2. 437. Sum of Floor DivisionsCount every divisor of every number up to a trillion200 XP30 min
  3. 443. Digit Sums Over a RangeAdd up every digit of every number between two giants220 XP40 min
  4. 459. Path in the Stern-Brocot TreeEvery positive fraction has an address in one endless tree230 XP45 min
  5. 464. Count the Perfect PowersSquares, cubes and higher powers, all the way to a billion billion240 XP45 min
  6. 475. K-th Number in Dictionary OrderSort a billion numbers like words and pick one out250 XP45 min
  7. 499. Sum of Euler's TotientHow many fractions between 0 and 1 have a small denominator?280 XP60 min

Other topics

Or see every challenge, with study plans, today's challenge and duels.