Count integers up to N that are equal to at least 2 nd power of any integer exceeding 1 | C # program for the above approach ; 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
using System ; using System . Collections . Generic ; class GFG { static void printNumberOfPairs ( int N ) { HashSet < int > st = new HashSet < int > ( ) ; for ( int i = 2 ; i * i <= N ; i ++ ) { int x = i ; while ( x <= N ) { x *= i ; if ( x <= N ) { st . Add ( x ) ; } } } Console . WriteLine ( st . Count ) ; } public static void Main ( string [ ] args ) { int N = 10000 ; printNumberOfPairs ( N ) ; } }