Given an positive large integer n. Count the number of positive divisors of n2 which are not divisible by any divisor of n(1 <= n <= 1012).
Input: 6 Output: 5 Explanation Total divisors of 62 are 9 i.e., 1, 2, 3, 4, 6, 9, 12, 18, 36 Total divisors of '6' are 4, 1, 2, 3, 6 Total divisor of '36' which are not divisible by divisors of '6' are '5' i.e., 4, 9, 12, 18, 36 Input: 8 Output: 3
Simple approach is to traverse for every divisor of n2 and count only those divisors which are not divisor of ‘n’. Time complexity of this approach is O(n).
Efficient approach is to use prime factorization to count total divisors of n2. A number ‘n’ can be represented as product of primes . Refer this to understand more.
Let for some primes p1 and p2. Squaring both the sides Total factors of n2 will be, Total factors of 'n' will be, Difference between the two gives the required answer
Time complexity: O(sqrt(n))
Auxiliary space: O(1)
- 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
- Sum of all divisors from 1 to n
- Count Divisors of n in O(n^1/3)
- Numbers with exactly 3 divisors
- Check if sum of divisors of two numbers are same
- Sum of common divisors of two numbers A and B
- Common Divisors of Two Numbers
- Sum of all the prime divisors of a number
- Count Divisors of Factorial
- Find number from its divisors
- Find the sum of the number of divisors
- Sum of divisors of factorial of a number
- Check if count of divisors is even or odd
- Find A and B from list of divisors
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.