Given n, find the smallest integer which has n factors or more. It may be assumed that the result is less than 1000001.
Input : n = 3 Output : 4 Explanation: 4 has factors 1, 2 and 4. Input : n = 2 Output : 2 Explanation: 2 has one factor 1 and 2.
There are many methods to calculate the number of factors, but the efficient one can be found here
Simple Approach: A simple approach will be to run a loop to find out the factors of a number. One for finding out the factors of a number in O(x) is to run a loop from 1 to x and see all numbers that divide x.
Time Complexity: O(x) for every number x that we try until we find answer or reach limit.
Efficient Approach:We can find out factors in sqrt(x)for every iteration.
Time Complexity: O(sqrt(x)) for every number x that we try until we find answer or reach limit.
Best Approach will be to traverse for every number and calculate the number of factors. Then check if the count is equal to or more then n then we get our desired smallest integer with n or more factors.
Below is the implementation of the above approach:
Time Complexity: O(log(max(number))) for every computing number we check before getting the answer.
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- Number which has the maximum number of distinct prime factors in the range M to N
- Biggest integer which has maximum digit sum in range from 1 to n
- Print all numbers whose set of prime factors is a subset of the set of the prime factors of X
- Find number of factors of N when location of its two factors whose product is N is given
- Check if a number exists having exactly N factors and K prime factors
- Maximum number of prime factors a number can have with exactly x factors
- Smallest non-zero substring which has any permutation divisible by 2^K
- Check whether a number has exactly three distinct factors or not
- Queries to find whether a number has exactly four distinct factors or not
- Find the row whose product has maximum count of prime factors
- Smallest integer > 1 which divides every element of the given array
- Count pairs (A, B) such that A has X and B has Y number of set bits and A+B = C
- Check if it is possible to create a matrix such that every row has A 1s and every column has B 1s
- Count number of rotated strings which have more number of vowels in the first half than second half
- Find numbers which are multiples of first array and factors of second array
- Find product of all elements at indexes which are factors of M for all possible sorted subsequences of length M
- Check if there exists a number with X factors out of which exactly K are prime
- Smallest number divisible by n and has at-least k trailing zeros
- Smallest number greater or equals to N such that it has no odd positioned bit set
- Smallest number whose square has N digits
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.