Count of interesting primes upto N | Function to check if a number is prime or not ; If n is divisible by any number between 2 and Math . sqrt ( n ) , it is not prime ; Function to check if a number is perfect square or not ; Find floating point value of square root of x . ; If square root is an integer ; Function to find the number of interesting primes less than equal to N . ; Check whether the number is prime or not ; Iterate for values of b ; Check condition for a ; Return the required answer ; Driver code
function isPrime ( n ) { let flag = 1 ; for ( let i = 2 ; i * i <= n ; i ++ ) { if ( n % i == 0 ) { flag = 0 ; break ; } } return ( flag == 1 ? true : false ) ; } function isPerfectSquare ( x ) { let sr = Math . sqrt ( x ) ; return ( ( sr - Math . floor ( sr ) ) == 0 ) ; } function countInterestingPrimes ( n ) { let answer = 0 ; for ( let i = 2 ; i <= n ; i ++ ) { if ( isPrime ( i ) ) { for ( let j = 1 ; j * j * j * j <= i ; j ++ ) { if ( isPerfectSquare ( i - j * j * j * j ) ) { answer ++ ; break ; } } } } return answer ; } let N = 10 ; document . write ( countInterestingPrimes ( N ) ) ;