Skip to content

Instantly share code, notes, and snippets.

@StarOrpheus
Created June 16, 2015 09:16
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save StarOrpheus/aa023888be2688d6f283 to your computer and use it in GitHub Desktop.
Save StarOrpheus/aa023888be2688d6f283 to your computer and use it in GitHub Desktop.
Bullshit
withFile = 1
if(withFile == 1):
fin = open('input.txt', 'r')
fout = open('output.txt', 'w')
def getl():
if(withFile == 0):
return input()
else:
return fin.readline()
def printl(s):
if(withFile == 0):
print(s)
else:
fout.write(str(s))
n = int(getl())
ans = 0
#x^3 + y^2 + z <= N
for x in range(1, 10**6):
# print(x)
yz = n - (x ** 3)
if(yz < 2):
break
l, r, y = 0, yz - 1, 0
while(l <= r):
mid = int((l + r) / 2)
if(yz - (mid ** 2) == 1):
y = mid
break
if(yz - (mid ** 2) > 1):
l = mid + 1
else:
y = r = mid - 1
ans += y * yz - int(y*(y + 1)*(2*y + 1)/6)
printl(ans)
if(withFile == 1):
fin.close()
fout.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment