Find minimum number of Log value needed to calculate Log upto N | C ++ program to find number of log values needed to calculate all the log values from 1 to N ; In this vector prime [ i ] will store true if prime [ i ] is prime , else store false ; Using sieve of Eratosthenes to find all prime upto N ; Function to find number of log values needed to calculate all the log values from 1 to N ; calculate primes upto N ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; #define MAX  1000005 NEW_LINE vector < bool > prime ( MAX , true ) ; void sieve ( int N ) { prime [ 0 ] = prime [ 1 ] = false ; for ( int i = 2 ; i <= N ; i ++ ) { if ( prime [ i ] ) { for ( int j = 2 ; i * j <= N ; j ++ ) prime [ i * j ] = false ; } } } int countLogNeeded ( int N ) { int count = 0 ; sieve ( N ) ; for ( int i = 1 ; i <= N ; i ++ ) { if ( prime [ i ] ) count ++ ; } return count ; } int main ( ) { int N = 6 ; cout << countLogNeeded ( N ) << endl ; return 0 ; }