Count all palindrome which is square of a palindrome | C # implementation of the above approach ; check if a number is a palindrome ; utility function used for reversing a string ; Function to return required count of palindromes ; Upper limit ; count odd length palindromes ; if s = '1234' ; then , t = '1234321' ; count even length palindromes ; if s = '1234' ; then , t = '12344321' ; Return count of super - palindromes ; Driver Code ; function call to get required answer
using System ; class GFG { static bool ispalindrome ( int x ) { int ans = 0 ; int temp = x ; while ( temp > 0 ) { ans = 10 * ans + temp % 10 ; temp = temp / 10 ; } return ans == x ; } static string Reverse ( string s ) { char [ ] charArray = s . ToCharArray ( ) ; Array . Reverse ( charArray ) ; return new string ( charArray ) ; } static int SuperPalindromes ( int L , int R ) { int LIMIT = 100000 ; int ans = 0 ; for ( int i = 0 ; i < LIMIT ; i ++ ) { string s = i . ToString ( ) ; string rs = s . Substring ( 0 , Math . Max ( 1 , s . Length - 1 ) ) ; rs = Reverse ( rs ) ; string p = s + rs ; int p_sq = ( int ) ( Math . Pow ( Int32 . Parse ( p ) , 2 ) ) ; if ( p_sq > R ) { break ; } if ( p_sq >= L && ispalindrome ( p_sq ) ) { ans = ans + 1 ; } } for ( int i = 0 ; i < LIMIT ; i ++ ) { string s = i . ToString ( ) ; string rs = Reverse ( s ) ; string p = s + rs ; int p_sq = ( int ) ( Math . Pow ( Int32 . Parse ( p ) , 2 ) ) ; if ( p_sq > R ) { break ; } if ( p_sq >= L && ispalindrome ( p_sq ) ) { ans = ans + 1 ; } } return ans ; } public static void Main ( ) { string L = "4" ; String R = "1000" ; Console . WriteLine ( SuperPalindromes ( Int32 . Parse ( L ) , Int32 . Parse ( R ) ) ) ; } }