Given a number n, the task is to find out whether this number is smith or not. A Smith Number is a composite number whose sum of digits is equal to the sum of digits in its prime factorization.
Input: n = 4 Output: 1 Explanation: Prime factorization = 2, 2; and 2 + 2 = 4 Therefore, 4 is a smith number.
Input: n = 6 Output: 0 Explanation: Prime factorization = 2, 3; and 2 + 3 is not 6. Therefore, 6 is a smith number.
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)
1 <= n <= 105
We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?Yes