VOOZH about

URL: https://www.geeksforgeeks.org/dsa/spy-number-sum-and-products-of-digits-are-same/

⇱ Spy Number (Sum and Products of Digits are same) - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Spy Number (Sum and Products of Digits are same)

Last Updated : 17 Feb, 2023

A number is said to be a Spy number if the sum of all the digits is equal to the product of all digits. 
Examples : 

Input : 1412
Output : Spy Number
Explanation : 
sum = (1 + 4 + 1 + 2) = 8
product = (1 * 4 * 1 * 2) = 8
since, sum == product == 8

Input : 132
Output : Spy Number
Explanation : 
sum = (1 + 3 + 2) = 6
product = (1 * 3 * 2) = 6
since, sum == product == 6


 


 


Output
The number is a Spy number

Time Complexity: O(log10n)
Auxiliary Space: O(1)


 

Comment