Number Theory
9 JavaScript number theory challenges, each with test cases you can run in the browser.
- gcd — Hard. Given two numbers a and b, return the greatest common divisor (GCD) of a and b. The GCD is the largest positive integer that divides both a
- sumPrimes — Medium. Sum all the prime numbers up to and including the provided number.
- smallestCommons — Medium. Find the smallest common multiple of the provided parameters that can be evenly divided by both, as well as by all sequential numbers in the
- lcm — Medium. Given two integers, find their least common multiple (LCM). The LCM is the smallest positive integer that is divisible by both numbers.
- primeFactors — Medium. Given a positive integer, return an array of its prime factors.
- isPerfectNumber — Medium. A perfect number is a positive integer that is equal to the sum of its proper positive divisors (the sum of its positive divisors excluding
- isArmstrongNumber — Medium. An Armstrong number is a number that is equal to the sum of its own digits each raised to the power of the number of digits. For example, 15
- digitalRoot — Easy. The digital root of a non-negative integer is the single-digit value obtained by an iterative process of summing digits, on each step using
- sieveOfEratosthenes — Hard. Implement the Sieve of Eratosthenes algorithm to find all prime numbers up to a given integer.