Count integers up to N that are equal to at least 2 nd power of any integer exceeding 1 | Function to count the integers up to N that can be represented as a ^ b , where a & b > 1 ; Initialize a HashSet ; Iterating over the range [ 2 , sqrt ( N ) ] ; Generate all possible power of x ; Multiply x by i ; If the generated number lies in the range [ 1 , N ] then insert it in HashSet ; Print the total count ; Driver Code
function printNumberOfPairs ( N ) { var st = new Set ( ) ; for ( let i = 2 ; i * i <= N ; i ++ ) { let x = i ; while ( x <= N ) { x *= i ; if ( x <= N ) { st . add ( x ) ; } } } document . write ( st . size ) ; } let N = 10000 ; printNumberOfPairs ( N ) ;