Given an integer n. Check whether the number n is superperfect number or not. A superperfect number is a positive integer which satisfies σ2(n) = σ(σ(n)) = 2n, where σ is divisor summatory function.
Input: n = 16 Output: yes Explanation: 16 is a superperfect number as σ(16) = 1 + 2 + 4 + 8 + 16 = 31, and σ(31) = 1 + 31 = 32, thus σ(σ(16)) = 32 = 2 × 16. Input: n = 8 Output: no Explanation: σ(8) = 1 + 2 + 4 + 8 = 15 and σ(15) = 1 + 3 + 5 + 15 = 24 thus ( σ(σ(8)) = 24 ) ≠ (2 * 8 = 26)
The idea is simply straightforward. We just iterate from 1 to sqrt(n) and find sum of all divisors of n, lets we call this sum as n1. Now we again need to iterate from 1 to sqrt(n1) and find sum of all divisors. After that we just need to check whether the resulted sum is equal to 2*n or not.
Output: Yes No
Time complexity: O(sqrt(n + n1)) where n1 is sum of divisors of n.
Auxiliary space: O(1)
Facts about Supernumbers:
- If n is an even superperfect number, then n must be a power of 2 i.e., 2k such that 2k+1 – 1 is a Mersenne prime.
- It is not known whether there are any odd superperfect numbers. An odd superperfect number n would have to be a square number such that either n or σ(n) is divisible by at least three distinct primes. There are no odd superperfect numbers below 7×1024
This article is contributed by Shubham Bansal. 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 write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
- Count number of trailing zeros in Binary representation of a number using Bitset
- Find minimum number to be divided to make a number a perfect square
- Count number of triplets with product equal to given number with duplicates allowed
- Smallest number dividing minimum number of elements in the array | Set 2
- Number of possible permutations when absolute difference between number of elements to the right and left are given
- Largest number dividing maximum number of elements in the array
- Given number of matches played, find number of teams in tournament
- Number of ways to split a binary number such that every part is divisible by 2
- Number of times the largest perfect square number can be subtracted from N
- Smallest number dividing minimum number of elements in the Array
- Find the number of positive integers less than or equal to N that have an odd number of digits
- Build Lowest Number by Removing n digits from a given number
- Find the smallest number whose digits multiply to a given number n
- Super Ugly Number (Number whose prime factors are in given set)
- Check whether all the rotations of a given number is greater than or equal to the given number or not
Improved By : jit_t