Wager Mage
Photo by Antony Trivet Pexels Logo Photo: Antony Trivet

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.

What does +180 mean odds?
What does +180 mean odds?

For an example of moneyline betting odds, you can bet the Eagles as a -150 favorite to win or the Giants as a +180 underdog to win. If you bet $100...

Read More »
Why is lower spread better?
Why is lower spread better?

A lower spread on the other hand indicates low volatility and high liquidity. Thus, there will be a smaller spread cost incurred when trading a...

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

When should you stop sports betting?
When should you stop sports betting?

Signs of a Sports Betting Addiction Unable to control the amount you spend on betting. Placing bets as an escape from difficult situations or...

Read More »
Is it smart to bet round robins?
Is it smart to bet round robins?

Round robins typically take a larger investment than traditional parlays, but it also increases potential profit while lessening the chance of a...

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

How is bonus measured?
How is bonus measured?

Annual bonus calculations are usually based on how well you did, like how much money you made or revenue. This is usually in line with the...

Read More »
How much do you tip a slot attendant on a jackpot?
How much do you tip a slot attendant on a jackpot?

There is no set amount for tipping after a jackpot. Many players will tip somewhere between a half to one percent of the jackpot. For a thousand...

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.

Are multi bets worth it?
Are multi bets worth it?

The odds on multis For a multi involving four $1.20 shots, you get odds of ($1.20 x $1.20 x $1.20 x $1.20 =) $2.07. Most punters love those multis...

Read More »
Who is the No 1 player in football history?
Who is the No 1 player in football history?

Anything you've ever seen a Brazilian footballer do well, it is because Pele has done it before them. He is arguably the greatest ever player on...

Read More »
Does a no contest count as a win?
Does a no contest count as a win?

Each fighter receives a NC counted in their record and is scored as neither a win nor a loss.

Read More »
How do you win a three leg parlay?
How do you win a three leg parlay?

A three-leg parlay is a parlay that consists of three bets. To win the parlay, bettors must win each individual leg. Nov 17, 2022

Read More »