Given an integer N. The task is to find the minimum number of log values needed to calculate all the log values from 1 to N using properties of the logarithm.
Input : N = 6 Output : 3 Value of log1 is already know, i.e. 0. Except this the three log values needed are, log2, log3, log5. Input : N = 4 Output : 2
One of the properties of log function is:
log(x.y) = log(x) + log(y)
Hence, to calculate log(x.y), we must know log values of x and y. Let us understand the concept using an example, for N = 6. Let ans denotes the number of log values needed to find all log values from 1 to 6.
- log(1)=0 (implicit).
- To calculate log(2), we must know its value prior, we can’t find this using property.so, ans become 1.
- To calculate log(3), we must know its value prior, we can’t find this using property.so, ans become 2.
- To calculate log(4), we can use property, log(4)=log(2.2)=log(2)+log(2).As we already find log(2) hence ans remains 2.
- To calculate log(5), we must know its value prior, we can’t find this using property.so, ans become 3.
- To calculate log(6), we can use property, log(6)=log(2.3)=log(2)+log(3).As we already find log(2) and log(3), hence ans remains 3.
The idea is very simple, on observing carefully you will find that you can’t calculate log values of prime number as it has no divisor(other than 1 and itself). So, the task reduces to find all prime numbers from 1 to N.
Below is the implementation of the above approach:
- Find minimum operations needed to make an Array beautiful
- Minimum number of letters needed to make a total of n
- Find all combinations that add upto given number
- Find square root of number upto given precision using binary search
- Minimum numbers needed to express every integer below N as a sum
- Minimum steps needed to cover a sequence of points on an infinite grid
- Find minimum number to be divided to make a number a perfect square
- Find sum of the series ?3 + ?12 +......... upto N terms
- Find Sum of Series 1^2 - 2^2 + 3^2 - 4^2 ..... upto n terms
- Find the sum of series 0.X + 0.XX + 0.XXX +... upto k terms
- Find the sum of series 3, -6, 12, -24 . . . upto N terms
- Count the number of currency notes needed
- Program to find the sum of the series 23+ 45+ 75+..... upto N terms
- Find sum of the series 1+22+333+4444+...... upto n terms
- Find the sum of the series 1+11+111+1111+..... upto n terms
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.