Store the unique primes
int [ ] cnt = new int [ 1000009 ] ; for ( int i = 0 ; i < 1000001 ; i ++ ) cnt [ i ] = 0 ; List < int > current_set = new List < int > ( ) ; for ( int i = 0 ; i < current . Count ; i ++ ) { cnt [ current [ i ] ] ++ ; if ( cnt [ current [ i ] ] == 1 ) current_set . Add ( current [ i ] ) ; }