Open In App
Related Articles

Hoax Number

Improve
Improve
Improve
Like Article
Like
Save Article
Save
Report issue
Report

Given a number ‘n’, check whether it is a hoax number or not. 
A Hoax Number is defined as a composite number, whose sum of digits is equal to the sum of digits of its distinct prime factors. It may be noted here that, 1 is not considered a prime number, hence it is not included in the sum of digits of distinct prime factors.
Examples : 
 

Input : 22
Output : A Hoax Number
Explanation : The distinct prime factors of 22 
are 2 and 11. The sum of their digits are 4, 
i.e 2 + 1 + 1 and sum of digits of 22 is also 4.

Input : 84
Output : A Hoax Number
Explanation : The distinct prime factors of 84 
are 2, 3 and 7. The sum of their digits are 12, 
i.e 2 + 3 + 4 and sum of digits of 84 is also 12.

Input : 19
Output : Not a Hoax Number
Explanation : By definition, a hoax number is 
a composite number.


 


The definition of Hoax numbers bears close resemblance with the definition of Smith Numbers. In fact, some of the Hoax numbers are also Smith numbers. It is apparent that those hoax numbers that do not have repeated factors in their prime decomposition, i.e square free number are also eligible Smith numbers.
Implementation 
1) First generate all distinct prime factors of the number ‘n’. 
2) If the ‘n’ is not a prime number, find the sum of digits of the factors obtained in step 1. 
3) Find the sum of digits of ‘n’. 
4) Check if the sums obtained in steps 2 and 3 are equal or not. 
5) If the sums are equal, ‘n’ is a hoax number. 
 

C++


                    

Java


                    

Python3


                    

C#


                    

PHP


                    

Javascript


                    

Output : 
 

A Hoax Number


Time Complexity: O(?n log n) 
Auxiliary Space: O(n)

Please suggest if someone has a better solution which is more efficient in terms of space and time.



Last Updated : 23 Jun, 2022
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads