P21788 [GeeksforGeeks] Smith number4132
普及
题目描述

Given a number n, the task is to find out whether this number is a Smith Number or not. A Smith Number is a composite number whose sum of digits is equal to the sum of digits of its prime factorization.

Example 1:
Input:
n = 4
Output:
1
Explanation:
Prime factorization = 2, 2; and 2 + 2 = 4
Therefore, 4 is a Smith Number.
Example 2:
Input:
n = 6
Output:
0
Explanation:
Prime factorization = 2, 3; and 2 + 3 is
not 6. Therefore, 6 is Not a Smith Number.

Your Task:
You don't need to read input or print anything. Your task is to complete the function smithNum() which takes an Integer n as input and returns the answer.

Expected Time Complexity: O(n)
Expected Auxiliary Space: O(n)

Constraints:
1 <= n <= 10^{5}

输入格式

见题面

输出格式

见题面

样例输入
n = 4
样例输出
1