Array ( [0] => [1] => questions [2] => Basic [3] => Strong-Number )
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).
First line contains a integer N.
Print Strongif it is Strong number else print not strong.
153
Not strong
145
Strong Number
53
Not strong
Login to see Discussion
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.
Login to see Solution