Given a number N. The task is to find the largest good number in the divisors of given number N. A number X is defined as the good number if there is no such positive integer a > 1 such that a^2 is a divisor of X.
Input: N = 10 Output: 10 In 1, 2, 5, 10. 10 is the largest good number Input: N = 12 Output: 6 In 1, 2, 3, 4, 6, 12. 6 is the largest good number
Approach: Find all prime divisors of N. Assume they are p1, p2, …, pk (in O(sqrt(n)) time complexity). If the answer is a, then we know that for each 1 <= I <= k, obviously, a is not divisible by pi^2 (and all greater powers of pi). So a <= p1 × p2 ×… × pk. And we know that p1 × p2 × … × pk is itself a good number. So, the answer is p1 × p2 ×…× pk.
Below is the implementation of above approach:
- Find sum of divisors of all the divisors of a natural number
- Find the number of integers x in range (1,N) for which x and x+1 have same number of divisors
- Find the number of good permutations
- Find number from its divisors
- Find the sum of the number of divisors
- Find all divisors of a natural number | Set 2
- Find all divisors of a natural number | Set 1
- Find the number of divisors of all numbers in the range [1, n]
- Program to find count of numbers having odd number of divisors in given range
- Find largest sum of digits in all divisors of n
- Querying maximum number of divisors that a number in a given range has
- Check if a number is divisible by all prime divisors of another number
- First triangular number whose number of divisors exceeds N
- Find largest prime factor of a number
- Find largest number smaller than N with same set of 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 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.