Open In App

Sastry Numbers

Last Updated : 24 Mar, 2021
Improve
Improve
Like Article
Like
Save
Share
Report

Given an integer N, the task is to check N is a Sastry number.
 

A number N is a Sastry Number if N concatenated with N + 1 gives a perfect square
 

Examples: 
 

Input: N = 183 
Output: Yes 
Explanation: 
183 + 184 = 183184 = 4282
Input: N = 28 
Output: No 
 

 

Approach: The idea is to convert the number to string and concatenate N and (N + 1) and then again convert it to an integer. Now we just have to check if the final number is a perfect square. If yes then the given number is a Sastry number.
Below is the implementation of the above approach:
 

Output

Yes

References: OEIS
 

 


Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads