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]
- Count numbers from range whose prime factors are only 2 and 3
- K-Primes (Numbers with k prime factors) in a range
- 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
- Common prime factors of two numbers
- Maximum factors formed by 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.