C ++ implementation of above approach
#include <bits/stdc++.h> NEW_LINE using namespace std ; bool prime [ 1000000 + 5 ] ; void findPrime ( ) { memset ( prime , true , sizeof ( prime ) ) ; prime [ 1 ] = false ; for ( int p = 2 ; p * p <= 1000000 ; p ++ ) {