Check whether a number is semiprime or not | Utility function to check whether number is semiprime or not ; If number is greater than 1 , add it to the count variable as it indicates the number remain is prime number ; Return '1' if count is equal to '2' else return '0' ; Function to print ' True ' or ' False ' according to condition of semiprime ; Driver code
< ? php function checkSemiprime ( $ num ) { $ cnt = 0 ; for ( $ i = 2 ; $ cnt < 2 && $ i * $ i <= $ num ; ++ $ i ) while ( $ num % $ i == 0 ) $ num /= $ i ; ++ $ cnt ; if ( $ num > 1 ) ++ $ cnt ; return $ cnt == 2 ; } function semiprime ( $ n ) { if ( checkSemiprime ( $ n ) ) echo " True STRNEWLINE " ; else echo " False STRNEWLINE " ; } $ n = 6 ; semiprime ( $ n ) ; $ n = 8 ; semiprime ( $ n ) ; ? >