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:
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.
- Find sum of inverse of the divisors when sum of divisors and the number is given
- Find sum of divisors of all the divisors of a natural number
- Check if a number has an odd count of odd divisors and even count of even divisors
- Divisors of n-square that are not divisors of n
- Maximum possible prime divisors that can exist in numbers having exactly N divisors
- Check if count of even divisors of N is equal to count of odd divisors
- Find all good indices in the given Array
- Find largest sum of digits in all divisors of n
- Find the number of good permutations
- Find the minimum number of elements that should be removed to make an array good
- Find the shortest distance between any pair of two different good nodes
- Find the good permutation of first N natural numbers
- Print all Good numbers in given range
- Sum of all second largest divisors after splitting a number into one or more parts
- Minimum number of elements that should be removed to make the array good
- Check whether a number is Good prime or not
- Program to find count of numbers having odd number of divisors in given range
- Sum of Digits of the Good Strings
- Find numbers with K odd divisors in a given range
- Find numbers with n-divisors in a given range
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.