A number n is said to be Powerful Number if for every prime factor p of it, p2 also divides it. For example:- 36 is a powerful number. It is divisible by both 3 and square of 3 i.e, 9.
The first few Powerful Numbers are:
1, 4, 8, 9, 16, 25, 27, 32, 36, 49, 64 ….
Given a number n, our task is to check if this is powerful or not.
Input: 27 Output: YES Input: 32 Output: YES Input: 12 Output: NO
The idea is based on the fact that if a number n is powerful, then all prime factors of it and their squares should be divisible by n. We find all prime factors of given number. And for every prime factor, we find the highest power of it that divides n. If we find a prime factor whose highest dividing power is 1, we return false. If highest dividing power of all prime factors is more than 1, we return true.
Below is implementation of above idea.
This article is contributed by Harsh Agarwal. 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 write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
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.
- Length of largest subarray whose all elements Powerful number
- Length of longest Powerful number subsequence in an Array
- Count the nodes in the given tree whose weight is a powerful number
- Number of factors of very large number N modulo M where M is any prime number
- Find minimum number to be divided to make a number a perfect square
- How to check if a given number is Fibonacci number?
- Find the smallest number whose digits multiply to a given number n
- Find n'th number in a number system with only 3 and 4
- Build Lowest Number by Removing n digits from a given number
- Count number of ways to divide a number in 4 parts
- Querying maximum number of divisors that a number in a given range has
- Check if a number is a power of another number
- Find the Largest number with given number of digits and sum of digits
- Finding number of digits in n'th Fibonacci number
- Smallest number by rearranging digits of a given number
- Super Ugly Number (Number whose prime factors are in given set)
- Number with maximum number of prime factors
- Convert a number m to n using minimum number of given operations
- Determine whether a given number is a Hyperperfect Number
- Find count of digits in a number that divide the number
Improved By : jit_t