Affluent Savvy
Photo by Ann H Pexels Logo Photo: Ann H

What is an astonishing number?

Astonishing Number is a number N whose representation can be decomposed into two parts, a and b, such that N is equal to the sum of the integers from a to b and a + b = N where '+' denotes concatenation. Few Astonishing Numbers are: 15, 27, 429, 1353, 1863, 3388, 3591, 7119..

What is rare in astrology?
What is rare in astrology?

After Aquarians, Aries and Sagittarius are the rarest zodiac signs. What all three of these signs lack in numbers, however, they make up for in...

Read More »
Where can I invest my money to get high returns?
Where can I invest my money to get high returns?

11 Safe Investments With High Returns to Consider in 2022-23 Introduction. Investment Types. Fixed Deposits (FD) Public Provident Fund (PPF) ABSLI...

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 »

Astonishing Number is a number N whose representation can be decomposed into two parts, a and b, such that N is equal to the sum of the integers from a to b and a + b = N where ‘+’ denotes concatenation.

Few Astonishing Numbers are:

15, 27, 429, 1353, 1863, 3388, 3591, 7119..

Check if N is an Astonishing number

Given a number N, the task is to check if N is an Astonishing Number or not. If N is an Astonishing Number then print “Yes” else print “No”.

Examples:

Input: N = 429

Output: Yes

Explanation:

429 = 4 + 5 + 6 …….. + 29, where a = 4, b = 29

and a + b = 429 where + denotes concatenation

Input: N = 28

Output: No

Approach: The idea is to run two loops of i and j, to find the sum of all integers from i till the sum becomes >= N. If at any point of time the sum becomes equals to N then we will also check if the concatenation of i and j equal to N or not. If equals then the number is an Astonishing number

Below is the implementation of the above approach:

C++

#include using namespace std; int concat( int a, int b) { string s1 = to_string(a); string s2 = to_string(b); string s = s1 + s2; int c = stoi(s); return c; } bool isAstonishing( int n) { for ( int i = 1; i < n; i++) { int sum = 0; for ( int j = i; j < n; j++) { sum += j; if (sum == n) { int concatenation = concat(i, j); if (concatenation == n) { return true ; } } } } return false ; } int main() { int n = 429; if (isAstonishing(n)) cout << "Yes" ; else cout << "No" ; return 0; } Java import java.io.*; class GFG{ static int concat( int a, int b) { String s1 = Integer.toString(a); String s2 = Integer.toString(b); String s = s1 + s2; int c = Integer.parseInt(s); return c; } static boolean isAstonishing( int n) { for ( int i = 1 ; i < n; i++) { int sum = 0 ; for ( int j = i; j < n; j++) { sum += j; if (sum == n) { int concatenation = concat(i, j); if (concatenation == n) { return true ; } } } } return false ; } public static void main (String[] args) { int n = 429 ; if (isAstonishing(n)) System.out.println( "Yes" ); else System.out.println( "No" ); } } Python3 def concat(a, b): s1 = str (a) s2 = str (b) s = s1 + s2 c = int (s) return c def isAstonishing(n): for i in range (n): sum = 0 for j in range (i, n): sum + = j if ( sum = = n): concatenation = concat(i, j) if (concatenation = = n): return True return False n = 429 if (isAstonishing(n)): print ( 'Yes' ) else : print ( 'No' ) C#

Which star is responsible for beauty?
Which star is responsible for beauty?

Venus may have been named after the most beautiful deity of the Roman (and Greek) pantheons because it shone the brightest among the five planets...

Read More »
Can dogs have mashed potatoes?
Can dogs have mashed potatoes?

Yes, as long as the potatoes are roasted and not boiled and no salt, seasonings, milk or butter is added your pet can enjoy this all-time favourite...

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 concat( int a, int b) { String s1 = a.ToString(); String s2 = b.ToString(); String s = s1 + s2; int c = Int32.Parse(s); return c; } static bool isAstonishing( int n) { for ( int i = 1; i < n; i++) { int sum = 0; for ( int j = i; j < n; j++) { sum += j; if (sum == n) { int concatenation = concat(i, j); if (concatenation == n) { return true ; } } } } return false ; } public static void Main(String[] args) { int n = 429; if (isAstonishing(n)) Console.WriteLine( "Yes" ); else Console.WriteLine( "No" ); } } Javascript

Output: Yes

Time Complexity: O(n)

Auxiliary Space: O(1)

Do ants hate peppermint or cinnamon?
Do ants hate peppermint or cinnamon?

My favorite essential oil to keep ants away is peppermint! I have had excellent luck using peppermint oil and have never seen ants cross a...

Read More »
What signs can Leo beat?
What signs can Leo beat?

Who Are Leos Compatible With: Leo Compatibility Chart Communication Friendship Virgo Medium High Libra Medium High Scorpio Low Low Sagittarius High...

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 »
Is cinnamon good for urinary tract infection?
Is cinnamon good for urinary tract infection?

Some studies show that cinnamon compounds prevent the colonization of E. coli in the bladder and urethra. This is the bacteria responsible for most...

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 zodiac is luckiest?
Which zodiac is luckiest?

Sagittarius. Sagittarius has luck on its side. In fact, three of our four astrology experts consider it the luckiest sign of them all (our fourth...

Read More »