Thursday, August 28, 2025

Sastry Numbers

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
 

 

Feeling lost in the world of random DSA topics, wasting time without progress? It’s time for a change! Join our DSA course, where we’ll guide you on an exciting journey to master DSA efficiently and on schedule.
Ready to dive in? Explore our Free Demo Content and join our DSA course, trusted by over 100,000 neveropen!

RELATED ARTICLES

Most Popular

Dominic
32245 POSTS0 COMMENTS
Milvus
80 POSTS0 COMMENTS
Nango Kala
6615 POSTS0 COMMENTS
Nicole Veronica
11787 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11833 POSTS0 COMMENTS
Shaida Kate Naidoo
6729 POSTS0 COMMENTS
Ted Musemwa
7011 POSTS0 COMMENTS
Thapelo Manthata
6684 POSTS0 COMMENTS
Umr Jansen
6699 POSTS0 COMMENTS