P | function to check if number n is a P - smooth number or not ; prime factorise it by 2 ; if the number is divisible by 2 ; check for all the possible numbers that can divide it ; prime factorize it by i ; stores the maximum if maximum and i , if i divides the number ; if n at the end is a prime number , then it a divisor itself ; Driver Code
function check ( n , p ) { let maximum = - 1 ; while ( ! ( n % 2 ) ) { maximum = Math . max ( maximum , 2 ) n = n / 2 ; } var i ; for ( i = 3 ; i * i <= n ; i += 2 ) { while ( n % i == 0 ) { maximum = Math . max ( maximum , i ) ; n = n / i ; } } if ( n > 2 ) maximum = Math . max ( maximum , n ) ; if ( maximum <= p ) return true ; else return false ; } let n = 24 , p = 7 ; if ( check ( n , p ) ) document . write ( " " ) ; else document . write ( " " ) ;