あなたが何を求めているのかは明確ではありませんが、私は推測しようとします。
z^z = a
まず、実数の方程式を解きz
ます。それぞれ、切り捨てu
と切り上げを行いますv
。z
3つの候補の中(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 = 1023
5^4 = 625
2000
x = 4
y = 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)