Affluent Savvy
Photo by Виталий Адуцкевич Pexels Logo Photo: Виталий Адуцкевич

What is the superpower of a number?

The Superpower is the highest power among the power of primes in the factorisation of a number n.

Why do people pray facing east?
Why do people pray facing east?

Nearly all Christian apologetic tracts published in the 7th century AD in the Syriac and Arabic languages explicated that the reason that...

Read More »
How much does the average 70 year old have in savings?
How much does the average 70 year old have in savings?

According to data from the Federal Reserve, the average amount of retirement savings for 65- to 74-year-olds is just north of $426,000. Aug 18, 2021

Read More »
Awaken your dormant DNA ability to attract wealth effortlessly
Awaken your dormant DNA ability to attract wealth effortlessly

The simple yet scientifically proven Wealth DNA method laid out in the report allows you to effortlessly start attracting the wealth and abundance you deserve.

Learn More »

Given an integer . The task is to find the superpower from the factorization of . The Superpower is the highest power among the power of primes in the factorisation of a number n.

Examples:

Input : n = 32 Output : 5 Input : n = 240 Output : 4 For finding the superpower of any given number , we have to complete the factorisation of n, and find out highest power among all of the prime factors. Note: Using Sieve for the purpose of storing list of primes is useful in terms of optimization.

Algorithm :

Iterate over primes and calculate the factorization of n.

For each prime among the stored list of primes and which is also a factor of n,

find its power and check it for super power.

Below is the implementation of the above approach:

C++

#include #define MAX 100000 using namespace std; bool prime[100002]; void SieveOfEratosthenes() { memset (prime, true , sizeof (prime)); for ( int p = 2; p * p <= MAX; p++) if (prime[p] == true ) for ( int i = p * 2; i <= MAX; i += p) prime[i] = false ; } int superpower( int n) { SieveOfEratosthenes(); int superPower = 0, factor = 0; int i = 2; while (n > 1 && i <= MAX) { if (prime[i]) { factor = 0; while (n % i == 0 && n > 1) { factor++; n = n / i; } if (superPower < factor) superPower = factor; } i++; } return superPower; } int main() { int n = 256; cout << superpower(n); return 0; } Java class GFG{ static int MAX= 100000 ; static boolean [] prime= new boolean [ 100002 ]; static void SieveOfEratosthenes() { for ( int p = 2 ; p * p <= MAX; p++) if (prime[p] == false ) for ( int i = p * 2 ; i <= MAX; i += p) prime[i] = true ; } static int superpower( int n) { SieveOfEratosthenes(); int superPower = 0 , factor = 0 ; int i = 2 ; while (n > 1 && i <= MAX) { if (!prime[i]) { factor = 0 ; while (n % i == 0 && n > 1 ) { factor++; n = n / i; } if (superPower < factor) superPower = factor; } i++; } return superPower; } public static void main(String[] args) { int n = 256 ; System.out.println(superpower(n)); } } Python3 MAX = 100000 ; prime = [ True ] * 100002 ; def SieveOfEratosthenes(): p = 2 ; while (p * p < = MAX ): if (prime[p] = = True ): i = p * 2 ; while (i < = MAX ): prime[i] = False ; i + = p; p + = 1 ; def superpower(n): SieveOfEratosthenes(); superPower = 0 ; factor = 0 ; i = 2 ; while (n > 1 and i < = MAX ): if (prime[i]): factor = 0 ; while (n % i = = 0 and n > 1 ): factor + = 1 ; n = int (n / i); if (superPower < factor): superPower = factor; i + = 1 ; return superPower; n = 256 ; print (superpower(n)); C#

What did the Prophet wash his hair with?
What did the Prophet wash his hair with?

This only suggests that the Prophet took elaborate care of his hair. Lady Ayesha confirms this in the following Hadith: “God's messenger used to...

Read More »
How do you build wealth in your 40s from nothing?
How do you build wealth in your 40s from nothing?

Your 40s are the ideal time to begin building wealth. ... 9 ways to build wealth in your 40s Increase your mortgage payments. ... Pay off debt now....

Read More »
Awaken your dormant DNA ability to attract wealth effortlessly
Awaken your dormant DNA ability to attract wealth effortlessly

The simple yet scientifically proven Wealth DNA method laid out in the report allows you to effortlessly start attracting the wealth and abundance you deserve.

Learn More »

class GFG { static int MAX = 100000; static bool [] prime = new bool [100002]; static void SieveOfEratosthenes() { for ( int p = 2; p * p <= MAX; p++) if (prime[p] == false ) for ( int i = p * 2; i <= MAX; i += p) prime[i] = true ; } static int superpower( int n) { SieveOfEratosthenes(); int superPower = 0, factor = 0; int i = 2; while (n > 1 && i <= MAX) { if (!prime[i]) { factor = 0; while (n % i == 0 && n > 1) { factor++; n = n / i; } if (superPower < factor) superPower = factor; } i++; } return superPower; } static void Main() { int n = 256; System.Console.WriteLine(superpower(n)); } } PHP 1 && $i <= $MAX ) { if ( $prime [ $i ]) { $factor = 0; while ( $n % $i == 0 && $n > 1) { $factor ++; $n = $n / $i ; } if ( $superPower < $factor ) $superPower = $factor ; } $i ++; } return $superPower ; } $n = 256; echo superpower( $n ); ?> Javascript

What is the best time to make a wish?
What is the best time to make a wish?

You can start making wishes at any time of the day, but when you make a wish at 11:11 it's even more powerful. Anytime you happen to see this time...

Read More »
How much should I have saved by 35?
How much should I have saved by 35?

So, to answer the question, we believe having one to one-and-a-half times your income saved for retirement by age 35 is a reasonable target. It's...

Read More »
Awaken your dormant DNA ability to attract wealth effortlessly
Awaken your dormant DNA ability to attract wealth effortlessly

The simple yet scientifically proven Wealth DNA method laid out in the report allows you to effortlessly start attracting the wealth and abundance you deserve.

Learn More »

Output: 8

Where do rich people keep their money?
Where do rich people keep their money?

Stocks and Mutual Funds Many millionaires and billionaires made their money — at least in part — by investing in the stock market, or by owning...

Read More »
Is $2 million enough to retire at 65?
Is $2 million enough to retire at 65?

Retirees with $2 million can enjoy a comfortable retirement, especially with interest added. Retiring early can cut into that savings due to early...

Read More »
Awaken your dormant DNA ability to attract wealth effortlessly
Awaken your dormant DNA ability to attract wealth effortlessly

The simple yet scientifically proven Wealth DNA method laid out in the report allows you to effortlessly start attracting the wealth and abundance you deserve.

Learn More »
What color is gratitude?
What color is gratitude?

pink The most popular color associated with gratitude is pink. Pink is universally recognized as the color of love for yourself and love for...

Read More »
Awaken your dormant DNA ability to attract wealth effortlessly
Awaken your dormant DNA ability to attract wealth effortlessly

The simple yet scientifically proven Wealth DNA method laid out in the report allows you to effortlessly start attracting the wealth and abundance you deserve.

Learn More »
Who is the forbidden woman in Proverbs 5?
Who is the forbidden woman in Proverbs 5?

We now begin a topic that Solomon will continue to address into chapter seven: the Adulteress. In Proverbs, the Adulteress (or Forbidden Woman) is...

Read More »