Affluent Savvy
Photo by Shawn Stutzman Pexels Logo Photo: Shawn Stutzman

Which number is mystery?

A mystery number is a number that can be expressed as the sum of two numbers and those two numbers should be the reverse of each other.

What zodiac signs Cannot control their anger?
What zodiac signs Cannot control their anger?

Here are a few zodiac signs who have anger issues, according to astrology. Aquarius. An Aquarius has the worst of anger. ... Virgo. A Virgo is also...

Read More »
Where do you touch a man when hugging?
Where do you touch a man when hugging?

Wrap one hand behind his back, just above his butt. Place the other hand around his neck so that your fingers rest where his neck meets his...

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 »

Given a number, check whether it is a mystery number or not. A mystery number is a number that can be expressed as the sum of two numbers and those two numbers should be the reverse of each other.

Examples:

Input : n = 121

Output : 29 92 Input : n = 22

Output : 11 11

The idea is to try every possible pair smaller than or equal to n.

Below is the implementation of the above approach.

C++

#include using namespace std; int reverseNum( int x) { string s = to_string(x); reverse(s.begin(), s.end()); stringstream ss(s); int rev = 0; ss >> rev; return rev; } bool isMysteryNumber( int n) { for ( int i=1; i <= n/2; i++) { int j = reverseNum(i); if (i + j == n) { cout << i << " " << j; return true ; } } cout << "Not a Mystery Number" ; return false ; } int main() { int n = 121; isMysteryNumber(n); return 0; } Java class GFG { static int reverseNum( int x) { String s = Integer.toString(x); String str= "" ; for ( int i=s.length()- 1 ;i>= 0 ;i--) { str=str+s.charAt(i); } int rev=Integer.parseInt(str); return rev; } static boolean isMysteryNumber( int n) { for ( int i= 1 ; i <= n/ 2 ; i++) { int j = reverseNum(i); if (i + j == n) { System.out.println( i + " " + j); return true ; } } System.out.println( "Not a Mystery Number" ); return false ; } public static void main(String []args) { int n = 121 ; isMysteryNumber(n); } } Python3 def reverseNum(x): s = str (x) s = s[:: - 1 ] return int (s) def isMysteryNumber(n): for i in range ( 1 , n / / 2 + 1 ): j = reverseNum(i) if i + j = = n: print (i, j) return True print ( "Not a Mystery Number" ) return False n = 121 isMysteryNumber(n) C# using System; class GFG { static int reverseNum( int x) { string s = x.ToString(); string str= "" ; for ( int i=s.Length-1;i>=0;i--) { str=str+s[i]; } int rev=Int32.Parse(str); return rev; } static bool isMysteryNumber( int n) { for ( int i=1; i <= n/2; i++) { int j = reverseNum(i); if (i + j == n) { Console.WriteLine( i + " " + j); return true ; } } Console.WriteLine( "Not a Mystery Number" ); return false ; } public static void Main() { int n = 121; isMysteryNumber(n); } } PHP

Who is the God of love female?
Who is the God of love female?

Aphrodite Who is Aphrodite? Aphrodite is the ancient Greek goddess of sexual love and beauty, identified with Venus by the Romans. She was known...

Read More »
Do you have to report inheritance money to IRS?
Do you have to report inheritance money to IRS?

Inheritances are not considered income for federal tax purposes, whether you inherit cash, investments or property. However, any subsequent...

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 »

Javascript

Output: 29 92

Time Complexity: O(n)

Auxiliary Space: O(log 10 n)

Which twin lives longest?
Which twin lives longest?

There is one particular power though which twins possess, longevity. Fraternal twins live longer than singletons and identical twins longer still....

Read More »
Which prayer is for wealth?
Which prayer is for wealth?

Prayer for Abundance and Prosperity You have created me in Your image, let Your gifts abundantly fill my cup until it overflows. Bless me with the...

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 4 most abundant elements of life?
What are the 4 most abundant elements of life?

The elements that are present in the highest quantities in living organisms are oxygen, carbon, hydrogen, nitrogen, sulfur, and phosphorus. These...

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 »
How do you make affirmations work faster?
How do you make affirmations work faster?

Practice affirming yourself every day Start with 3 to 5 minutes at least twice a day. Try saying affirmations upon waking up and getting into bed,...

Read More »