You are given a range of numbers, from lower number to higher number (both inclusive). Consider all the factors of these numbers except 1, the task is to find the factor which appears the maximum number of times. If more than one number have maximum frequency than print anyone of them.
Input : lower=10 higher=14 Output : The factor with maximum frequency is 2. Input : lower=11 higher=11 Output : The factor with maximum frequency is 11.
If we have a range of numbers, say 10 to 14. Then the factors other than 1 will be:
In the above case, frequency(2)= 3, which is maximum on comparing with other factors.
1. If lower = higher, then all factors will have frequency 1. So we can print any number which is factor, since every number is a factor of itself so we print the same number.
2. Otherwise, we print ‘2’ as it will always be true for a range of numbers.
The most frequent factor 2
Time Complexity: O(1)
- Count all the numbers in a range with smallest factor as K
- Queries on the sum of prime factor counts in a range
- Count of integers of the form (2^x * 3^y) in the range [L, R]
- Count integers in the range [A, B] that are not divisible by C and D
- Count integers in a range which are divisible by their euler totient value
- Integers from the range that are composed of a single distinct digit
- Ways to form an array having integers in given range such that total sum is divisible by 2
- Find the number of integers x in range (1,N) for which x and x+1 have same number of divisors
- Median in a stream of integers (running integers)
- Count of integers in a range which have even number of odd digits and odd number of even digits
- Find the most frequent digit without using array/string
- Prime Factor
- N-th prime factor of a given number
- k-th prime factor of a given number
- Print the kth common factor of two numbers
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.