Given an integer N, the task is to check if the number is a Prime power number. If yes, then print the number along with its power which is equal to N. Else print -1.
A prime power is a positive integer power of a single prime number.
For example: 7 = 71, 9 = 32 and 32 = 25 are prime powers, while 6 = 2 × 3, 12 = 22 × 3 and 36 = 62 = 22 × 32 are not. (The number 1 is not counted as a prime power.)
Note: If there are no such prime number, print -1.
Input: N = 49
N can be represented as a power of prime number 7.
N = 49 = 72
Input: N = 100
N cannot be represented as a power of any prime number.
Approach: The idea is use Seive of Eratosthenes to find all the prime number. Then, Iterate over all the prime numbers and check that if any prime number divides the given number N, if yes then divide it until it becomes 1 or not divisible by that prime number. Finally, check that the number is equal to 1, If yes then return prime number otherwise given number cannot be expressed as a prime number raised to some power.
Below is the implementation of the above approach:
7 ^ 2
- Power of a prime number ‘r’ in n!
- Check if a large number is divisible by a number which is a power of 2
- Finding power of prime number p in n!
- Check if given number is a power of d where d is a power of 2
- Check if a number is divisible by all prime divisors of another number
- Check if a number is a power of another number
- Check if a number is Prime, Semi-Prime or Composite for very large numbers
- Check if a prime number can be expressed as sum of two Prime Numbers
- Check if a number can be expressed as power | Set 2 (Using Log)
- Check whether a given Number is Power-Isolated or not
- Given a HUGE number check if it's a power of two.
- Check if a number can be expressed as x^y (x raised to power y)
- Check if a number is power of k using base changing method
- Check if a number is a Pythagorean Prime or not
- Check whether a number is circular prime or not
- Check if a number is Full Prime
- C Program to Check Whether a Number is Prime or not
- Check whether N is a Dihedral Prime Number or not
- Check if the first and last digit of number N is prime and their sum is less than K
- Check a number for Permutable Prime
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 Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.
Improved By : SURENDRA_GANGWAR