Given:
f(x)=Sum[x/n!] for all positive integers n, where the [] brackets define the integer part of x (e.g. [pi]=3)
What is x, if f(x)=1215
x can be anywhere on the interval [709,710)
or 709 + a where 0 <= a < 1
Since the title says "integers only", if this applies to x, then x=709.
But if the title applies only to f(x), then x can be anywhere in that interval.
--------
def fact(n):
if n == 1 or n == 0:
return 1
ans = 1
for i in range(n):
ans *= (i+1)
return ans
def sumf(x):
ans = 0
for n in range(1,100):
ans += int(x/fact(n))
return ans
lo = 500
hi = 1000
error = 10000
while error > 0:
guess = (lo+hi)/2
f = sumf(guess)
if f > 1215:
hi = guess
error = abs(f - 1215)
elif f < 1215:
lo = guess
error = abs(f - 1215)
elif f == 1215:
print('The answer is ', guess)
error = abs(f - 1215)
for d in range(200):
i = 708+d/100
if sumf(i) == 1215:
print(i, sumf(i))
|
Posted by Larry
on 2023-09-25 08:57:50 |