Given a range [l, r], the task is to find the sum of all the even factors of the numbers from the given range.
Input: l = 6, r = 8
factors(6) = 1, 2, 3, 6, evenfactors(6) = 2, 6 sumEvenFactors(6) = 2 + 6 = 8
factors(7) = 1, 7, No even factors
factors(8) = 1, 2, 4, 8, evenfactors(8) = 2, 4, 8 sumEvenFactors(8) = 2 + 4 + 8 = 14
Therefore sum of all even factors = 8 + 14 = 22
Input: l = 1, r = 10
Approach: We can modify Sieve Of Eratosthenes to store the sum of all even factors of a number at it’s corresponding index. Then we will make a prefix array to store sum upto that index. And now each query can be answered in O(1) using prefix[r] – prefix[l – 1].
Below is the implementation of the above approach:
- Sum of all odd factors of numbers in the range [l, r]
- K-Primes (Numbers with k prime factors) in a range
- Count numbers from range whose prime factors are only 2 and 3
- Count numbers in a range having GCD of powers of prime factors equal to 1
- Print all numbers whose set of prime factors is a subset of the set of the prime factors of X
- Number of elements with even factors in the given range
- Number of elements with odd factors in given range
- Generation of n numbers with given set of factors
- Maximum factors formed by two numbers
- Common prime factors of two numbers
- Count common prime factors of two numbers
- Efficient program to print the number of factors of n numbers
- Number of distinct prime factors of first n natural numbers
- Number which has the maximum number of distinct prime factors in the range M to N
- Find number of factors of N when location of its two factors whose product is N is given
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.