Skills101
← All practice quizzes

Quiz: Number Theory for Coding

5 questions · new set on every retakeNo time limitPass: 60%+10 XP on first pass

The maths that coding tests use again and again: GCD and LCM with Euclid's algorithm, prime checks, the Sieve of Eratosthenes, prime factors, modular arithmetic and fast exponentiation.

Log in to take the quiz

Free account · see your score, answers and explanations, earn XP

  1. Question 1

    Why does Euclid's algorithm use gcd(a, b) = gcd(b, a % b)?

  2. Question 2

    What does this print?

    import math
    print(math.gcd(48, 36), 48 * 36 // math.gcd(48, 36))
    
  3. Question 3

    To check whether n is prime, why is it enough to try divisors up to √n?

  4. Question 4

    In the Sieve of Eratosthenes, why start crossing out multiples of p from p × p?

  5. Question 5

    What does this print?

    N = 30
    is_p = [True] * (N + 1)
    is_p[0] = is_p[1] = False
    for p in range(2, 6):
        if is_p[p]:
            for k in range(p * p, N + 1, p):
                is_p[k] = False
    print(sum(is_p))
    
🎯 Today’s placement challenge — 10 questions, no login. Can you score 10/10?Take today’s challenge →