Numbers less than N which are product of exactly two distinct prime numbers | Function to check whether a number is a PerfectSquare or not ; Function to check if a number is a product of exactly two distinct primes ; Function to find numbers that are product of exactly two distinct prime numbers . ; Vector to store such numbers ; insert in the vector ; Print all numbers till n from the vector ; Driver Code
< ? php function isPerfectSquare ( $ x ) { $ sr = sqrt ( $ x ) ; return ( ( $ sr - floor ( $ sr ) ) == 0 ) ; } function isProduct ( $ 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 findNumbers ( $ N ) { $ vec = array ( ) ; for ( $ i = 1 ; $ i <= $ N ; $ i ++ ) { if ( isProduct ( $ i ) && ! isPerfectSquare ( $ i ) ) { array_push ( $ vec , $ i ) ; } } for ( $ i = 0 ; $ i < sizeof ( $ vec ) ; $ i ++ ) { echo $ vec [ $ i ] . " " ; } } $ N = 30 ; findNumbers ( $ N ) ;