Linked Questions
13 questions linked to/from Check if one integer is an integer power of another
-14 votes
2 answers
516 views
Check if number is divisible by a power of two [duplicate]
Find the highest power of two that divides x, a 64-bit integer, or return -1. The zero case is not defined, since it dives any power of two, so your method can return any number. I tried using the ...
-2 votes
2 answers
262 views
Algorithm to find whether a number is a power of the other [duplicate]
How to find out whether a number b is can be expressed as a power of another number c and to find the corresponding exponent? Without using math.h or recursion. The numbers are of the type int! This ...
71 votes
26 answers
79k views
How to check if an integer is a power of 3?
I saw How to check if an integer is a power of 2?, and pop up the idea of how to check for power of 3.
20 votes
9 answers
8k views
C++: how can I test if a number is power of ten?
I want to test if a number double x is an integer power of 10. I could perhaps use cmath's log10 and then test if x == (int) x? edit: Actually, my solution does not work because doubles can be very ...
15 votes
4 answers
19k views
How can I compare the performance of log() and fp division in C++?
I’m using a log-based class in C++ to store very small floating-point values (as the values otherwise go beyond the scope of double). As I’m performing a large number of multiplications, this has the ...
9 votes
4 answers
2k views
Certain Power of Sum of Digits of N == N (running too slowly)
I'm trying to write a Python script that finds all integers (N) where a certain power of the sum of the digits of N is equal to N. For example, N=81 qualifies, because 8 + 1 = 9, and a certain power ...
1 vote
6 answers
2k views
For 2 numbers, how to test if one is an integer power of the other?
For integers x, y, and n, (only x and y are given) test if xn = y? If x = 8, y = 512, then n = 3 so that is true. But if x = 8 and y = 500, n would have to be around 2.98 (not an integer) so the ...
1 vote
9 answers
4k views
Python Recursion Exercise
I am doing exercise on Singpath and I am stuck at this question. This question is under recursion exercises but I have no idea what the question means. A number, a, is a power of b if it is ...
5 votes
1 answer
175 views
Numerical accuracy of an integer solution to an exponential equation
I have an algorithm that relies on integer inputs x, y and s. For input checking and raising an exception for invalid arguments I have to make sure that there is a natural number n so that x*s^n=y Or ...
0 votes
3 answers
173 views
Does the standard library of C# have an easy way to check whether a number is a power of another number?
I'm trying to see if there is a good way to find whether, given ints b and n, there exists an int a such that a^n=b. In other words, something more efficient than the bad solution I wrote below ...
0 votes
1 answer
222 views
Whether given number is a power of any other natural number php?
I tried to find For a given positive integer Z, check if Z can be written as PQ, where P and Q are positive integers greater than 1. If Z can be written as PQ, return 1, else return 0 I tried ...
0 votes
0 answers
217 views
Rounding behaviour of Math.Log
I'm trying to determine if a give integer n is a power of three. My approach is to take the base 3 log of n and check if there's anything after the decimal point of the result: int n = 243; double ...
0 votes
1 answer
75 views
Checking if an integer is an integer power of another?
This is identical to the question found on Check if one integer is an integer power of another, but I am wondering about the complexity of a method that I came up with to solve this problem. Given an ...