Count of sets possible using integers from a range [ 2 , N ] using given operations that are in Equivalence Relation | Javascript program for tha above approach ; Sieve of Eratosthenes to find primes less than or equal to N ; Function to find number of Sets ; Handle Base Case ; Set which contains less than or equal to N / 2 ; Number greater than N / 2 and are prime increment it by 1 ; If the number is prime Increment answer by 1 ; Input ; Function Call
let prime = new Array ( 100001 ) ; function SieveOfEratosthenes ( n ) { for ( let i = 0 ; i < prime . length ; i ++ ) { prime [ i ] = true ; } for ( let p = 2 ; p * p <= n ; p ++ ) { if ( prime [ p ] == true ) { for ( let i = p * p ; i <= n ; i += p ) prime [ i ] = false ; } } } function NumberofSets ( N ) { SieveOfEratosthenes ( N ) ; if ( N == 2 ) { document . write ( 1 ) ; } else if ( N == 3 ) { document . write ( 2 ) ; } else { let ans = 1 ; for ( let i = Math . floor ( N / 2 ) + 1 ; i <= N ; i ++ ) { if ( prime [ i ] ) { ans += 1 ; } } document . write ( ans ) ; } } let N = 9 ; NumberofSets ( N ) ;