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 function
function isPerfectSquare ( x ) { sr = Math . sqrt ( x ) ; return ( ( sr - Math . floor ( sr ) ) == 0 ) ; } function isProduct ( num ) { var cnt = 0 ; for ( var i = 2 ; cnt < 2 && ( i * i ) <= num ; ++ i ) { while ( num % i == 0 ) { num = parseInt ( num / i ) ; ++ cnt ; } } if ( num > 1 ) ++ cnt ; return cnt == 2 ; } function findNumbers ( N ) { vec = [ ] ; for ( var i = 1 ; i <= N ; i ++ ) { if ( isProduct ( i ) && ! isPerfectSquare ( i ) ) { vec . push ( i ) ; } } for ( var i = 0 ; i < vec . length ; i ++ ) { document . write ( vec [ i ] + " " ) ; } } var N = 30 ; findNumbers ( N ) ;