Check whether a given number is Polydivisible or Not | function to check polydivisible number ; digit extraction of input number ; store the digits in an array ; n contains first i digits ; n should be divisible by i ; Driver code
function check_polydivisible ( n ) { let N = n ; let digit = [ ] ; while ( n > 0 ) { digit . push ( n % 10 ) ; n = parseInt ( n / 10 , 10 ) ; } digit . reverse ( ) ; let flag = true ; n = digit [ 0 ] ; for ( let i = 1 ; i < digit . length ; i ++ ) { n = n * 10 + digit [ i ] ; if ( n % ( i + 1 ) != 0 ) { flag = false ; break ; } } if ( flag ) document . write ( N + " " + " " ) ; else document . write ( N + " " ) ; } let n = 345654 ; check_polydivisible ( n ) ;