Given an integer N, the task is to find all of its divisors using its prime factorization.
Input: N = 6
Output: 1 2 3 6
Input: N = 10
Output: 1 2 5 10
Approach: As every number greater than 1 can be represented in it’s prime factorization as p1a1*p2a2*……*pkak, here pi is a prime number, k ≥ 1 and ai is a positive integer.
Now all the possible divisors can be generated recursively if the count of occurrence of every prime factor of n is known. For every prime factor pi, it can be included x times where 0 ≤ x ≤ ai. First, find the prime factorization of n using this approach and for every prime factor, store it with the count of it’s occurrence.
Below is the implementation of the above approach:
1 3 2 6
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.
- Count occurrences of a prime number in the prime factorization of every element from the given range
- Sum of Factors of a Number using Prime Factorization
- Sum of all the prime divisors of a number
- Count of the non-prime divisors of a given number
- Check if a number has prime count of divisors
- Check if a number is divisible by all prime divisors of another number
- Check if a number can be expressed as a product of exactly K prime divisors
- Product of divisors of a number from a given list of its prime factors
- Maximum possible prime divisors that can exist in numbers having exactly N divisors
- Pollard's Rho Algorithm for Prime Factorization
- Prime Factorization using Sieve O(log n) for multiple queries
- Find sum of divisors of all the divisors of a natural number
- Find sum of inverse of the divisors when sum of divisors and the number is given
- Sum of all prime divisors of all the numbers in range L-R
- Count of numbers below N whose sum of prime divisors is K
- Find the number of integers x in range (1,N) for which x and x+1 have same number of divisors
- Querying maximum number of divisors that a number in a given range has
- Find the largest good number in the divisors of given number N
- First triangular number whose number of divisors exceeds N
- Palindromic divisors of a number
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. 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.