Affluent Savvy
Photo by Pixabay Pexels Logo Photo: Pixabay

What is a 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!

What is the most special stone?
What is the most special stone?

1. Blue Diamond. The stunning blue diamond is arguably the most prized of all precious gemstones. A flawless example is so rare that whenever one...

Read More »
What is a symbol of wealth?
What is a symbol of wealth?

Money is the symbol of wealth. Hua 2001 insists that it is a kind of currency and... a symbol of wealth. This example is from Wikipedia and may be...

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#

What are signs that your manifestation is coming?
What are signs that your manifestation is coming?

5 Signs Your Manifestation Is On Its Way You Keep Seeing Signs & Synchronicities. When your manifestation – or something even better suited to you...

Read More »
What is a mirror twin?
What is a mirror twin?

The term mirror twin is used to describe a type of identical, or monozygotic, twin pairing in which the twins are matched as if they're looking...

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)

How can I make 1000 a day?
How can I make 1000 a day?

How to Make 1,000 a Day Get Paid to Do Market Research. One of the fastest ways you can begin making money is by giving your opinion. ... Get Paid...

Read More »
Is Harry Potter A Virgo?
Is Harry Potter A Virgo?

Born on July 31st, Harry is a Leo. Like a classic Leo, he constantly puts the well-being of others before his own. Born on September 19th, Hermione...

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 are the 3 intentions of anointing with oil in the Old Testament?
What are the 3 intentions of anointing with oil in the Old Testament?

What are the 3 intentions of anointing with oil in the Old Testament? Anointing oils were used to anoint priests, furnishings in the tabernacle to...

Read More »
What causes low self esteem?
What causes low self esteem?

Causes of low self-esteem Unhappy childhood where parents (or other significant people such as teachers) were extremely critical. Poor academic...

Read More »