あなたが何を求めているのかは明確ではありませんが、私は推測しようとします。
z^z = aまず、実数の方程式を解きzます。それぞれ、切り捨てuと切り上げを行いますv。z3つの候補の中(u,u)から(v,u)、(u,v)を超えない最大のものを選択しますa。
例:ケースを検討しa = 2000ます。z^z = 2000数値解法(下記参照)で解き、近似解を得z = 4.8278228255818725ます。u = 4を取得するために切り上げv = 5ます。これで、、、の3つの候補ができまし4^4 = 256た。それらはすべて、よりも小さいので、最大の答えを与えるもの、つまり、を採用します。4^5 = 10235^4 = 6252000x = 4y = 5
これがPythonコードです。関数solve_approxはあなたが望むことをします。に適していa >= 3ます。私はあなたが事件a = 1にそしてa = 2あなた自身で対処できると確信しています。
import math
def solve(a):
""""Solve the equation x^x = a using Newton's method"""
x = math.log(a) / math.log(math.log(a)) # Initial estimate
while abs (x ** x - a) > 0.1:
x = x - (x ** x - a) / (x ** x * (1 + math.log(x)))
return x
def solve_approx(a):
""""Find two integer numbers x and y such that x^y is smaller than
a but as close to it as possible, and try to make x and y as equal
as possible."""
# First we solve exactly to find z such that z^z = a
z = solve(a)
# We round z up and down
u = math.floor(z)
v = math.ceil(z)
# We now have three possible candidates to choose from:
# u ** zdwon, v ** u, u ** v
candidates = [(u, u), (v, u), (u, v)]
# We filter out those that are too big:
candidates = [(x,y) for (x,y) in candidates if x ** y <= a]
# And we select the one that gives the largest result
candidates.sort(key=(lambda key: key[0] ** key[1]))
return candidates[-1]
ここに小さなデモがあります:
>>> solve_approx(5)
solve_approx(5)
(2, 2)
>>> solve_approx(100)
solve_approx(100)
(3, 4)
>>> solve_approx(200)
solve_approx(200)
(3, 4)
>>> solve_approx(1000)
solve_approx(1000)
(5, 4)
>>> solve_approx(1000000)
solve_approx(1000000)
(7, 7)