- Related Questions & Answers
- Check if a number can be expressed as a^b in C++
- Check if a number can be expressed as x^y (x raised to power y) in C++
- Check if a number can be expressed as a^b in Python
- Check if a number can be expressed as 2^x + 2^y in C++
- Check if a number can be expressed as sum two abundant numbers in C++
- Check if a number can be expressed as a sum of consecutive numbers in C++
- Check if a prime number can be expressed as sum of two Prime Numbers in Python
- C++ Program to Check Whether a Number can be Expressed as Sum of Two Prime Numbers
- Check if an integer can be expressed as a sum of two semi-primes in Python
- Check if a number can be written as sum of three consecutive integers in C++
- Check if a number can be represented as a sum of 2 triangular numbers in C++
- Find ways an Integer can be expressed as sum of n-th power of unique natural numbers in C++
- Check if a number is a power of another number in C++
- Check if a number can be represented as sum of non zero powers of 2 in C++
- C program for a number to be expressed as a sum of two prime numbers.

- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who

Here we will check whether we can represent a number as power, like a^{b} or not. Suppose a number 125 is present. This can be represented as 5^{3}. Another number 91 cannot be represented as power of some integer value.

isRepresentPower(num): Begin if num = 1, then return true for i := 2, i2 <= num, increase i by 1, do val := log(a)/log(i) if val – int(val) < 0.0000000001, then return true done return false End

#include<iostream> #include<cmath> using namespace std; bool isRepresentPower(int num) { if (num == 1) return true; for (int i = 2; i * i <= num; i++) { double val = log(num) / log(i); if ((val - (int)val) < 0.00000001) return true; } return false; } int main() { int n = 125; cout << (isRepresentPower(n) ? "Can be represented" : "Cannot be represented"); }

Can be represented

Advertisements