The Smith Number

HardAcc. 79.2%
+40 XP 20

Digital Harmony

A composite number is a Smith Number if the sum of its digits equals the sum of the digits of its prime factors (excluding 1). Example: 4937775 Prime Factors: 3, 5, 5, 65837 $ o$ digit sums match!

The Assignment

Your function receives a parameter num.

  1. Check if num is composite (not prime).
  2. Calculate the sum of digits of num.
  3. Find all prime factors of num.
  4. Calculate the sum of digits of all those prime factors combined.
  5. Print "true" if the sums match, else "false".

01EXAMPLE 1

Inputnum = 666
Outputtrue

Explanation: Digits 6+6+6=18. Factors 2, 3, 3, 37. Digit sums: 2+3+3+(3+7)=18.

Constraints

  • Must use loops for factoring and digit summing.
  • Strict comparison check.
MathLoopsDigits
JavaScript
Loading...
3 Hidden

Input Arguments

num666

Expected Output

true

Click RUN to test your solution