The Prime Factorizer

MediumAcc. 88.4%
+30 XP 12

Basic Decomposition

Every integer can be uniquely represented as a product of prime numbers. Example: $12 = 2 imes 2 imes 3$.

The Assignment

Your function receives a parameter named num.

  1. Start with a divisor at 2.
  2. Use a while loop that continues as long as num is greater than 1.
  3. Inside the loop:
    • If num is divisible by divisor:
      • Print the divisor.
      • Update num to num / divisor.
    • Otherwise:
      • Increment the divisor to find the next candidate.

01EXAMPLE 1

Inputnum = 12
Output2 2 3

Explanation: Finds all prime building blocks.

Constraints

  • Print each factor on a new line.
  • The loop must naturally skip non-prime divisors.
MathLoops
JavaScript
Loading...
3 Hidden

Input Arguments

num12

Expected Output

2
2
3

Click RUN to test your solution