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
< ? php function check ( $ n , $ p ) { $ maximum = -1 ; while ( ! ( $ n % 2 ) ) { $ maximum = max ( $ maximum , 2 ) ; $ n = $ n / 2 ; } for ( $ i = 3 ; $ i <= sqrt ( $ n ) ; $ i += 2 ) { while ( $ n % $ i == 0 ) { $ maximum = max ( $ maximum , $ i ) ; $ n = $ n / $ i ; } } if ( $ n > 2 ) $ maximum = max ( $ maximum , $ n ) ; return ( $ maximum <= $ p ) ; } $ n = 24 ; $ p = 7 ; if ( check ( $ n , $ p ) ) echo ( " yes " ) ; else echo ( " no " ) ; ? >