Array ( [0] => [1] => questions [2] => Codevita-Previous-Questions [3] => Strong-Number ) Basic | Strong Number | THE INQUISITIVE





Strong Number

LEVEL:Beginner

Description

Given a integer N. You have to find the given number is a strong number or not (Strong number is a number, sum of factorial of every digit equal to given number).

Input Format

First line contains a integer N.

Output Format

Print Strongif it is Strong number else print not strong.


Example 1:

Input
153
Output
Not strong
Example 2:

Input
145
Output
Strong Number
Example 3:

Input
53
Output
Not strong

oops

Login to see Discussion




Approach


Approach 1: every time finding factorial

Step-i) copy given number in temp variable
Step-ii) get remainder of number by dividing it with 10
Step-iii) get the factorial of that number using the method
Step-iv) add it to the answer variable
Step-v) repeat steps ii,iii and iv till num>0
Step-vi) return the answer

Time Complexity: O(logn)
Space Complexity: O(1)

Approach 2: Maintaining a factorial array

Step-i) create a array of size 10 and fill it with factorial of 1 to 9
Step-ii) get remainder of number by dividing it with 10
Step-iii) get the factorial of that number from array
Step-iv) add it to the answer variable
Step-v) repeat steps ii,iii and iv till num>0
Step-vi) return the answer

Time Complexity: O(logn)
Space Complexity: O(1)


Note :

Let us know if you can come up with a better approach, mail us at support@theinquisitive.in Your approach will be reviewed and posted with credits to you.

oops

Login to see Solution