Powerful Number - GeeksforGeeks
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.
Examples:
Input: 27 Output: YES Input: 32 Output: YES Input: 12 Output: NO
We strongly recommend you to minimize your browser and try this yourself first.
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.
Read full article from Powerful Number - GeeksforGeeks
No comments:
Post a Comment