Find minimum number of Log value needed to calculate Log upto N | Javascript 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
MAX = 1000005 var prime = Array ( MAX ) . fill ( true ) ; function sieve ( N ) { prime [ 0 ] = prime [ 1 ] = false ; for ( var i = 2 ; i <= N ; i ++ ) { if ( prime [ i ] ) { for ( var j = 2 ; i * j <= N ; j ++ ) prime [ i * j ] = false ; } } } function countLogNeeded ( N ) { var count = 0 ; sieve ( N ) ; for ( var i = 1 ; i <= N ; i ++ ) { if ( prime [ i ] ) count ++ ; } return count ; } var N = 6 ; document . write ( countLogNeeded ( N ) ) ;