Given a range [l, r], the task is to find the sum of all the odd factors of the numbers from the given range.
Input: l = 6, r = 8
factors(6) = 1, 2, 3, 6, oddfactors(6) = 1, 3 sum_Odd_Factors(6) = 1 + 3 = 4
factors(7) = 1, 7, oddfactors(6) = 1 7, sum_Odd_Factors(7) = 1 + 7 = 8
factors(8) = 1, 2, 4, 8, oddfactors(6) = 1, sum_Odd_Factors(8) = 1 = 1
Therefore sum of all odd factors = 4 + 8 + 1 = 13
Input: l = 1, r = 10
Approach: We can modify Sieve Of Eratosthenes to store sum of all odd 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 even 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 odd factors in given range
- Number of elements with even factors in the 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
- Number of distinct prime factors of first n natural numbers
- Efficient program to print the number of factors of n numbers
- Number which has the maximum number of distinct prime factors in the range M to N
- Sum of all even numbers in range L and 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.