- Thread starter
- Admin
- #1
- Feb 14, 2012
- 3,595
How many of the first 1000 positive integers can be expressed in the form $\lfloor 2x \rfloor+\lfloor 4x \rfloor+\lfloor 6x \rfloor+\lfloor 8x \rfloor$, where $x$ is a real number?
# -*- coding: utf-8 -*-
def f(x):
r = int(2*x)
r += int(4*x)
r += int(6*x)
r += int(8*x)
return r
def solve(n):
x0 = 0
f0 = -n
x1 = n
f1 = f(x1) - n
v = 0
while v < 201:
x = 0.5*(x0 + x1)
ff = f(x) - n
v += 1
if ff == 0:
return x
if ff < 0:
#root between x and x1
x0 = x
f0 = ff
if ff > 0:
#root between x0 and x
x1 = x
f1 = ff
return -1
sol = 0
nsol = 0
for i in range(1,1001):
t = solve(i)
if(t == -1):
nsol += 1
print(i, 'no solution')
else:
sol += 1
print(i, t)
print('')
print(sol, 'numbers possible')
print(nsol, 'numbers not possible')