Linked Questions

-14 votes
2 answers
516 views

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 ...
Ilya Gazman's user avatar
  • 32.5k
-2 votes
2 answers
262 views

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 ...
KLMM's user avatar
  • 93
71 votes
26 answers
79k views

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.
Mask's user avatar
  • 34.4k
20 votes
9 answers
8k views

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 ...
Giovanni Funchal's user avatar
15 votes
4 answers
19k views

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 ...
Ventzi Zhechev's user avatar
9 votes
4 answers
2k views

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 ...
5u2ie's user avatar
  • 93
1 vote
6 answers
2k views

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 ...
Justin's user avatar
  • 25.7k
1 vote
9 answers
4k views

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 ...
Michelle Chan's user avatar
5 votes
1 answer
175 views

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 ...
Mario Dekena's user avatar
0 votes
3 answers
173 views

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 ...
Ms Corlib's user avatar
0 votes
1 answer
222 views

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 ...
Hardy Mathew's user avatar
0 votes
0 answers
217 views

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 ...
Adam's user avatar
  • 10.4k
0 votes
1 answer
75 views

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 ...
roulette01's user avatar
  • 2,502