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
- Count number of trailing zeros in Binary representation of a number using Bitset
- Number which has the maximum number of distinct prime factors in the range M to N
- Given number of matches played, find number of teams in tournament
- Number of times the largest perfect square number can be subtracted from N
- Count number of ways to divide a number in 4 parts
- Count number of digits after decimal on dividing a number
- Find the maximum number of composite summands of a number
- Super Ugly Number (Number whose prime factors are in given set)
- Count Number of animals in a zoo from given number of head and legs
- Querying maximum number of divisors that a number in a given range has
- Find maximum number that can be formed using digits of a given number
- Find the number of ways to divide number into four parts such that a = c and b = d
- Build Lowest Number by Removing n digits from a given number
Improved By : jit_t