Given two integers L and R, the task is to calculate the value of the expression:
Input: L = 6, R = 12
Input: L = 5, R = 6
Approach: It can be observed that .
Hence, the answer will be (1 / L) – (1 / (R + 1)).
Below is the implementation of the above approach:
Time Complexity: O(1)
GeeksforGeeks has prepared a complete interview preparation course with premium videos, theory, practice problems, TA support and many more features. Please refer Placement 100 for details
- Find all possible outcomes of a given expression
- Find the minimum value of X for an expression
- Find the minimum value of the given expression over all pairs of the array
- Find a permutation of 2N numbers such that the result of given expression is exactly 2K
- Find minimum value of the expression by choosing K elements from given array
- Find the GCD that lies in given range
- Find XOR of numbers from the range [L, R]
- Find numbers with K odd divisors in a given range
- Find the smallest twins in given range
- Find the XOR of the elements in the given range [L, R] with the value K for a given set of queries
- Find sum in range L to R in given sequence of integers
- Find the occurrences of digit d in the range [0..n]
- Find the largest twins in given range
- Find numbers with n-divisors in a given range
- Find Prime Adam integers in the given range [L, R]
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.