Affluent Savvy
Photo by Tima Miroshnichenko Pexels Logo Photo: Tima Miroshnichenko

What is strong number?

Strong number is a special number whose sum of the factorial of digits is equal to the original number. For Example: 145 is strong number. Since, 1! + 4! + 5!

Which mantra is the king of all mantras?
Which mantra is the king of all mantras?

1. OM. The king of mantras. The OM is the sound of the universe, resonating at 432 Hz, this is the entire world in just one intensely pleasurable...

Read More »
What is the rarest to be born in?
What is the rarest to be born in?

Christmas, New Years, Christmas Eve, July 4th, Halloween, and some suspiciously Thanksgiving days all make the top 10 least common birthdays. Jul...

Read More »
Awaken your dormant DNA ability to attract wealth effortlessly
Awaken your dormant DNA ability to attract wealth effortlessly

The simple yet scientifically proven Wealth DNA method laid out in the report allows you to effortlessly start attracting the wealth and abundance you deserve.

Learn More »

Print all Strong numbers less than or equal to N

Given a number N, print all the Strong Numbers less than or equal to N. Strong number is a special number whose sum of the factorial of digits is equal to the original number. For Example: 145 is strong number. Since, 1! + 4! + 5! = 145.

Examples:

Input: N = 100

Output: 1 2

Explanation:

Only 1 and 2 are the strong numbers from 1 to 100 because

1! = 1, and

2! = 2 Input: N = 1000

Output: 1 2 145

Explanation:

Only 1, 2 and 145 are the strong numbers from 1 to 1000 because

1! = 1,

2! = 2, and

(1! + 4! + 5!) = 145

Approach: The idea is to iterate from [1, N] and check if any number between the range is strong number or not. If yes then print the corresponding number, else check for the next number.

Below is the implementation of the above approach:

C++

#include using namespace std; int factorial[] = { 1, 1, 2, 6, 24, 120, 720, 5040, 40320, 362880 }; bool isStrong( int N) { string num = to_string(N); int sum = 0; for ( int i = 0; i < num.length(); i++) { sum += factorial[num[i] - '0' ]; } return sum == N; } void printStrongNumbers( int N) { for ( int i = 1; i <= N; i++) { if (isStrong(i)) { cout << i << " " ; } } } int main() { int N = 1000; printStrongNumbers(N); return 0; } Java class GFG { static int [] factorial = { 1 , 1 , 2 , 6 , 24 , 120 , 720 , 5040 , 40320 , 362880 }; public static boolean isStrong( int N) { String num = Integer.toString(N); int sum = 0 ; for ( int i = 0 ; i < num.length(); i++) { sum += factorial[Integer .parseInt(num .charAt(i) + "" )]; } return sum == N; } public static void printStrongNumbers( int N) { for ( int i = 1 ; i <= N; i++) { if (isStrong(i)) { System.out.print(i + " " ); } } } public static void main(String[] args) throws java.lang.Exception { int N = 1000 ; printStrongNumbers(N); } } Python3 factorial = [ 1 , 1 , 2 , 6 , 24 , 120 , 720 , 5040 , 40320 , 362880 ] def isStrong(N): num = str (N) sum = 0 for i in range ( len (num)): sum + = factorial[ ord (num[i]) - ord ( '0' )] if sum = = N: return True else : return False def printStrongNumbers(N): for i in range ( 1 , N + 1 ): if (isStrong(i)): print (i, end = " " ) if __name__ = = "__main__" : N = 1000 printStrongNumbers(N) C#

Who is the youngest billionaire in the world?
Who is the youngest billionaire in the world?

Synopsis. Kim Jung-youn, daughter of Nexon-founder Kim Jung-ju, becomes the world's youngest billionaire thanks to her inheritance from her late...

Read More »
What zodiac signs will fall in love in 2023?
What zodiac signs will fall in love in 2023?

5 zodiac signs that will be lucky in love in 2023. Everyone hopes to find a compatible life partner in addition to a nice career, home, and...

Read More »
Awaken your dormant DNA ability to attract wealth effortlessly
Awaken your dormant DNA ability to attract wealth effortlessly

The simple yet scientifically proven Wealth DNA method laid out in the report allows you to effortlessly start attracting the wealth and abundance you deserve.

Learn More »

using System; class GFG{ static int [] factorial = { 1, 1, 2, 6, 24, 120, 720, 5040, 40320, 362880 }; public static bool isStrong( int N) { String num = N.ToString(); int sum = 0; for ( int i = 0; i < num.Length; i++) { sum += factorial[ int .Parse(num[i] + "" )]; } return sum == N; } public static void printStrongNumbers( int N) { for ( int i = 1; i <= N; i++) { if (isStrong(i)) { Console.Write(i + " " ); } } } public static void Main(String[] args) { int N = 1000; printStrongNumbers(N); } } Javascript

Output: 1 2 145

Time Complexity: O(N log 10 N)

Auxiliary Space: O(log 10 N)

Why is yellow a powerful color?
Why is yellow a powerful color?

The radiant color of yellow promotes happiness and optimism in the observer. Yellow is said to promote happiness more than any of the other major...

Read More »
Can you control your own luck?
Can you control your own luck?

It's true that some people are born with advantages, or events happen to us that are outside our control. You can always do something to build upon...

Read More »
Awaken your dormant DNA ability to attract wealth effortlessly
Awaken your dormant DNA ability to attract wealth effortlessly

The simple yet scientifically proven Wealth DNA method laid out in the report allows you to effortlessly start attracting the wealth and abundance you deserve.

Learn More »
Which mantra should we chant daily?
Which mantra should we chant daily?

1. OM. The king of mantras. The OM is the sound of the universe, resonating at 432 Hz, this is the entire world in just one intensely pleasurable...

Read More »
Awaken your dormant DNA ability to attract wealth effortlessly
Awaken your dormant DNA ability to attract wealth effortlessly

The simple yet scientifically proven Wealth DNA method laid out in the report allows you to effortlessly start attracting the wealth and abundance you deserve.

Learn More »
What zodiac signs go well together?
What zodiac signs go well together?

Individuals with their Sun in these two signs are also traditionally "compatible" with yours. Aries: Gemini, Aquarius. Taurus: Cancer, Pisces....

Read More »