Leaderboard
Showing:
Smith Number
Medium Accuracy: 16.67% Submissions: 18 Points: 4

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.

 

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 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 <= 105

to report an issue on this page.

Editorial

We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?

Yes

All Submissions

My Submissions:

Login to access your submissions.

Smith Number

Output Window