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.
- Count number of triplets with product equal to given number with duplicates allowed
- Find minimum number to be divided to make a number a perfect square
- Number which has the maximum number of distinct prime factors in the range M to N
- Queries on sum of odd number digit sums of all the factors of a number
- Count number of digits after decimal on dividing a number
- Find count of digits in a number that divide the number
- Find the largest good number in the divisors of given number N
- Count Number of animals in a zoo from given number of head and legs
- Count number of ways to divide a number in 4 parts
- Querying maximum number of divisors that a number in a given range has
- Build Lowest Number by Removing n digits from a given number
- Number of digits to be removed to make a number divisible by 3
- Check if a number is divisible by all prime divisors of another number
- Program to Convert Octal Number to Binary Number
- Print a number strictly less than a given number such that all its digits are distinct.
Improved By : jit_t