If $a$ is given how can I calculate $x^y$ and $y^x$ the fastest way? Is there any other way than brute forcing? How is this type of equation called?
Let's say $x$ and $y$ must be $>1$ and non negative integers.
If $a$ is given how can I calculate $x^y$ and $y^x$ the fastest way? Is there any other way than brute forcing? How is this type of equation called?
Let's say $x$ and $y$ must be $>1$ and non negative integers.
Let's analyze this a bit, assuming that $x \le y$:
For $x = 3$, you need to test $y = 3, 4, \dots, \lfloor \log_3 a \rfloor$.
...
So, let $a = 2^{64}-1$. Then, we have $246$ candidates for a solution:
\begin{align*} &x = 2 \quad \Rightarrow \quad y \in \{2,3,\dots,63\}, \\ &x = 3 \quad \Rightarrow \quad y \in \{3,4,\dots,40\}, \\ &x = 4 \quad \Rightarrow \quad y \in \{4,5,\dots,31\}, \\ &x = 5 \quad \Rightarrow \quad y \in \{5,6,\dots,27\}, \\ &x = 6 \quad \Rightarrow \quad y \in \{6,7,\dots,24\}, \\ &x = 7 \quad \Rightarrow \quad y \in \{7,8,\dots,22\}, \\ &x = 8 \quad \Rightarrow \quad y \in \{8,9,\dots,21\}, \\ &x = 9 \quad \Rightarrow \quad y \in \{9,10,\dots,20\}, \\ &x = 10 \quad \Rightarrow \quad y \in \{10,11,\dots,19\}, \\ &x = 11 \quad \Rightarrow \quad y \in \{11,12,\dots,18\}, \\ &x = 12 \quad \Rightarrow \quad y \in \{12,13,\dots,17\}, \\ &x = 13 \quad \Rightarrow \quad y \in \{13,14,\dots,17\}, \\ &x = 14 \quad \Rightarrow \quad y \in \{14,15,16\}, \\ &x = 15 \quad \Rightarrow \quad y \in \{16\}, \end{align*}
I draw two conclusions from here:
Bruteforcing is simple.
Only a negligible number of these systems ($246$ among the first $2^{64}-1$) have solutions.
It's easier to go through all possible $(x,y)$, construct all $246$ values of $(x,y,a)$, put them in a file or a database, and just search for a solution when one is needed (and, most likely, doesn't exist).
The larger your numbers are, the less likely it is that you'll have a solution for any given $a$, so there is no point in going beyond $64$ bit (actually, there is no point going even that far).
while
loop in any language will be very quick. For example, Mathematica on my computer (3+ years old) finds a solution for $$a = 2^{100000} - 1 = 2^{10^5} - 1$$ in about 3 seconds (it's $x \le 7740$). Notice that this number needs $10^5$ bits, i.e., around 12.5KiB of memory, so the arithmetic operations are quite slow (they need to be software-simulated, as the processor doesn't support that).
– Vedran Šego
Aug 07 '13 at 22:42
while
is elegant. If you prefer Lambert W function, check here.
– Vedran Šego
Aug 07 '13 at 23:01