Prepare for Math Interview Questions

Learn how to solve challenging math coding problems and prep for your technical interview.

  1. 3 ways to check if a value is prime

    A prime number is a natural number greater than 1 that has no positive divisors other than 1 and itself. A natural number greater than 1 that is not a prime number is called a composite number. Given an input value check if it's a prime.

  2. Finding all prime factors

    Given a number, return all the prime factors and their corresponding number of occurrences.

  3. Project Euler Problem 46: Goldbach's other conjecture

    It was proposed by Christian Goldbach that every odd composite number can be written as the sum of a prime and twice a square. For example,

    9 = 7 + 2 x 12
    15 = 7 + 2 x 22
    21 = 3 + 2 x 32
    25 = 7 + 2 x 32
    27 = 19 + 2 x 22

    It turns out the conjecture was false. What is the smallest odd composite that cannot be written as the sum of a prime and twice a square?

  4. Project Euler Problem 12: Highly divisible triangular number

    The sequence of triangle numbers is generated by adding the natural numbers. So the 7th triangle number would be 1 + 2 + 3 + 4 + 5 + 6 + 7 = 28. The first ten terms would be:

    1, 3, 6, 10, 15, 21, 28, 36, 45, 55, ...

    Let us list the factors of the first seven triangle numbers:

    1: 1
    3: 1,3
    6: 1,2,3,6
    10: 1,2,5,10
    15: 1,3,5,15
    21: 1,3,7,21
    28: 1,2,4,7,14,28

    We can see that 28 is the first triangle number to have over five divisors.

    What is the value of the first triangle number to have over five hundred divisors?

  5. Integer Right Triangles

    If p is the perimeter of a right angle triangle with integral length sides, {a,b,c}, there are exactly three solutions for p = 120: {20,48,52}, {24,45,51}, and {30,40,50}.

  6. Pluses and Minuses 1-9

    Write a program that outputs all possibilities to put + or - or nothing between the numbers 1

  7. Project Euler Problem 27: Quadratic Primes

    Euler discovered the remarkable quadratic formula:

    n2 + n + 41

    It turns out that the formula will produce 40 primes for the consecutive values n = 0 to 39. However, when n = 40, 402 + 40 + 41 = 40(40 + 1) + 41 is divisible by 41, and certainly when n = 41, 412 + 41 + 41 is clearly divisible by 41.

    The incredible formula  n2 − 79n + 1601 was discovered, which produces 80 primes for the consecutive values n = 0 to 79. The product of the coefficients, −79 and 1601, is −126479.

    Considering quadratics of the form:

    n² + an + b, where |a| < 1000 and |b| < 1000

    where |n| is the modulus/absolute value of ne.g. |11| = 11 and |−4| = 4

    Find the product of the coefficients, a and b, for the quadratic expression that produces the maximum number of primes for consecutive values of n, starting with n = 0.