40 lines
928 B
Python
Executable File
40 lines
928 B
Python
Executable File
#!/usr/bin/env python
|
|
#
|
|
from math import log10
|
|
|
|
|
|
def main():
|
|
for x, y, z, num_nodes in sorted(list(get_matches(90, 90)), key=lambda val: val[3]):
|
|
if num_nodes < 1000000:
|
|
print(f"{x}**{y} == {y}**{z} == {num_nodes}")
|
|
|
|
|
|
def get_matches(max_x: int, max_y: int):
|
|
for x in range(2, max_x):
|
|
for y in range(2, max_y):
|
|
diff, y_exp = check(x, y)
|
|
if diff == 0:
|
|
yield (x, y, y_exp, x**y)
|
|
|
|
|
|
def check(x: int, y: int):
|
|
num_nodes = x**y
|
|
# y**z = x**y
|
|
# zlogy = ylogx
|
|
# z = ylogx/logy
|
|
|
|
# flipped:
|
|
exp_for_y = y * log10(x) / log10(y)
|
|
# Round the exp for y to be a plain integer
|
|
exp_for_y = round(exp_for_y)
|
|
flipped_num_nodes = y**exp_for_y
|
|
|
|
# compare the num nodes after rounding to find a good fit with integers.
|
|
diff = abs(num_nodes - flipped_num_nodes)
|
|
|
|
return diff, exp_for_y
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|