Wager Mage
Photo by Ben Mack Pexels Logo Photo: Ben Mack

Which is the powerful number?

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.

How often should you 3 bet?
How often should you 3 bet?

When should you 3-bet? It is easy to understand 3-betting for value. When playing solid, aggressive poker, a good rule is to always 3-bet your...

Read More »
What does under 4.0 goals mean?
What does under 4.0 goals mean?

Under 4,5 : Less than 5 goals must be scored during the match to win. There are alternatives: Over 2: More than 2 goals must be scored during the...

Read More »

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

Approach:

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.

C++

#include using namespace std; bool isPowerful( int n) { while (n % 2 == 0) { int power = 0; while (n % 2 == 0) { n /= 2; power++; } if (power == 1) return false ; } for ( int factor = 3; factor <= sqrt (n); factor += 2) { int power = 0; while (n % factor == 0) { n = n / factor; power++; } if (power == 1) return false ; } return (n == 1); } int main() { isPowerful(20) ? cout << "YES

" : cout << "NO

" ; isPowerful(27) ? cout << "YES

" : cout << "NO

" ; return 0; } Java

class GFG { static boolean isPowerful( int n) { while (n % 2 == 0 ) { int power = 0 ; while (n % 2 == 0 ) { n /= 2 ; power++; } if (power == 1 ) return false ; } for ( int factor = 3 ; factor <= Math.sqrt(n); factor += 2 ) { int power = 0 ; while (n % factor == 0 ) { n = n / factor; power++; } if (power == 1 ) return false ; } return (n == 1 ); } public static void main(String[] args) { if (isPowerful( 20 )) System.out.print( "YES

" ); else System.out.print( "NO

Does anything beat a royal flush?
Does anything beat a royal flush?

As shown in the poker hand rankings chart, the order of poker rankings (from the highest to the lowest) is: Royal Flush, Straight Flush, Four-of-a-...

Read More »
What does under 2.75 goals mean?
What does under 2.75 goals mean?

Another example is if you bet on the Under 2.75 goals. In this example, half your bet is placed on the Under 2.5 goals and the other half is bet on...

Read More »

" ); if (isPowerful( 27 )) System.out.print( "YES

" ); else System.out.print( "NO

" ); } } Python3

import math def isPowerful(n): while (n % 2 = = 0 ): power = 0 while (n % 2 = = 0 ): n = n / / 2 power = power + 1 if (power = = 1 ): return False for factor in range ( 3 , int (math.sqrt(n)) + 1 , 2 ): power = 0 while (n % factor = = 0 ): n = n / / factor power = power + 1 if (power = = 1 ): return false return (n = = 1 ) print ( "YES" if isPowerful( 20 ) else "NO" ) print ( "YES" if isPowerful( 27 ) else "NO" ) C# using System; class GFG { static bool isPowerful( int n) { while (n % 2 == 0) { int power = 0; while (n % 2 == 0) { n /= 2; power++; } if (power == 1) return false ; } for ( int factor = 3; factor <= Math.Sqrt(n); factor += 2) { int power = 0; while (n % factor == 0) { n = n / factor; power++; } if (power == 1) return false ; } return (n == 1); } public static void Main() { if (isPowerful(20)) Console.WriteLine( "YES" ); else Console.WriteLine( "NO" ); if (isPowerful(27)) Console.WriteLine( "YES" ); else Console.WriteLine( "NO" ); } } PHP " : "NO

Does 2pair beat a flush?
Does 2pair beat a flush?

What is the order of poker hands? As shown in the poker hand rankings chart, the order of poker rankings (from the highest to the lowest) is: Royal...

Read More »
Can you deduct gambling losses if you have no winnings?
Can you deduct gambling losses if you have no winnings?

And if you have a particularly unlucky year, you cannot just deduct your losses without reporting any winnings. If the IRS allowed this, then it's...

Read More »

" ; echo $d ; $d = isPowerful(27) ? "YES

" : "NO

" ; echo $d ; ?> Javascript

Output NO YES

Time complexity: O(sqrt(n))

Auxiliary space: O(1)

References:

https://en.wikipedia.org/wiki/Powerful_number

This article is contributed by Harsh Agarwal. If you like GeeksforGeeks and would like to contribute, you can also write an article using write.geeksforgeeks.org or mail your article to review-team@geeksforgeeks.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.

What is the luckiest number between 1 and 200?
What is the luckiest number between 1 and 200?

1, 3, 7, 9, 13, 15, 21, 25, 31, 33, 37, 43, 49, 51, 63, 67, 69, 73, 75, 79, 87, 93, 99, 105, 111, 115, 127, 129, 133, 135, 141, 151, 159, 163, 169,...

Read More »
Why do people say COO instead of cool?
Why do people say COO instead of cool?

Those non-standard written forms showed some interesting regional patterning. Spelling cool as coo or koo turns out to be a California thing. (The...

Read More »
What Sportsbook gives the most free bets?
What Sportsbook gives the most free bets?

Best Free Bet Offers Betfred Sportsbook: First bet is matched up to $1500 if it comes out as a loss. FoxBet Sportsbook: Get up to $500 in a risk-...

Read More »
Are tipsters worth it?
Are tipsters worth it?

As with all elements of gambling, it is important to know that risk is still involved and paid tipsters are not a guaranteed way to win, but they...

Read More »