Palindromic divisors of a number | Function to check is num is palindromic or not ; Convert n to string str ; Starting and ending index of string str ; If char at s and e are not equals then return false ; Function to find palindromic divisors ; To sore the palindromic divisors of number n ; If n is divisible by i ; Check if number is a perfect square ; Check divisor is palindromic , then store it ; Check if divisors are palindrome ; Check if n / divisors is palindromic or not ; Print all palindromic divisors in sorted order ; Driver code ; Function call to find all palindromic divisors
function isPalindrome ( n ) { var str = ( n . toString ( ) ) ; var s = 0 , e = str . length - 1 ; while ( s < e ) { if ( str [ s ] != str [ e ] ) { return false ; } s ++ ; e -- ; } return true ; } function palindromicDivisors ( n ) { var PalindromDivisors = [ ] ; for ( var i = 1 ; i <= parseInt ( Math . sqrt ( n ) ) ; i ++ ) { if ( n % i == 0 ) { if ( n / i == i ) { if ( isPalindrome ( i ) ) { PalindromDivisors . push ( i ) ; } } else { if ( isPalindrome ( i ) ) { PalindromDivisors . push ( i ) ; } if ( isPalindrome ( n / i ) ) { PalindromDivisors . push ( n / i ) ; } } } } PalindromDivisors . sort ( ( a , b ) => a - b ) for ( var i = 0 ; i < PalindromDivisors . length ; i ++ ) { document . write ( PalindromDivisors [ i ] + " " ) ; } } var n = 66 ; palindromicDivisors ( n ) ;