# Python program to check whether given number is Hoax Number

In this article, we will learn how to check whether a given number is a Hoax Number in Python. A number is said to Hoax Number only when the sum of digits of its distinct prime factor of the given number is equal to the sum of digits of the given number.

Examples

Input: n = 22 Output: A Hoax number Explanation: The distinct prime factor of the 22 is 2, 11. The sum of the digits of its prime factors is 2+1+1 = 4. The sum of digits of given number is also 4 (i.e. 2+2) Input: n = 12 Output: Not a Hoax number Examplanation: The distinct prime factor of the 12 is 2, 3. The sum of the digits of its prime factors is 2+3 = 5. The sum of digits of given number is 3 (i.e. 1+2).

## Hoax Number in Python

1. Firstly, create a function primeFactors() to generate all the prime factors of n.

2. Now, calculate the sum of prime factors generated by primeFactors() function.

3. Calculate the sum of digits of n.

4. If the sum calculated in step 2 and step 3 are equal then the given number is a hoax number.

import math # function to calculate the prime factors def primeFactors(n) : result = [] if (n % 2 == 0) : while (n % 2 == 0) : n = int(n / 2) result.append(2) for i in range(3,int(math.sqrt(n)),2): if (n % i == 0) : while (n % i == 0) : n = int(n / i) result.append(i) if (n > 2) : result.append(n) return result # function to calulate the Hoax number def isHoax(n) : p_fac = primeFactors(n) if (p_fac[0] == n) : return False all_pf_sum = 0 for i in range(0,len(p_fac)): pf_sum = 0 while (p_fac[i] > 0): pf_sum += p_fac[i] % 10 p_fac[i] = int(p_fac[i] / 10) all_pf_sum += pf_sum sum_Ndigits = 0; while (n > 0): sum_Ndigits += n % 10 n = int(n / 10) return sum_Ndigits == all_pf_sum n = int(input("Enter the n value: ")); if (isHoax(n)): print ("n is a Hoax Number") else: print ("n is not a Hoax Number")

Output

Enter the n value: 22 n is a Hoax Number Enter the n value: 84 n is a Hoax Number Enter the n value: 25 n is not a Hoax Number

Also, read

## Leave a Reply