Program to check whether a number is Proth number or not | Utility function to check power of two ; Function to check if the Given number is Proth number or not ; Check if k divides n or not ; Check if n / k is power of 2 or not ; Update k to next odd number ; If we reach here means there exists no value of K Such that k is odd number and n / k is a power of 2 greater than k ; Get n ; Check n for Proth Number
function isPowerOfTwo ( n ) { return ( n && ! ( n & ( n - 1 ) ) ) ; } function isProthNumber ( n ) { let k = 1 ; while ( k < parseInt ( n / k ) ) { if ( n % k == 0 ) { if ( isPowerOfTwo ( parseInt ( n / k ) ) ) return true ; } k = k + 2 ; } return false ; } let n = 25 ; if ( isProthNumber ( n - 1 ) ) document . write ( " " ) ; else document . write ( " " ) ;