################
# sums of cubes

n = 1000
sum = 0
for i in range(1,n+1):
  sum += i**3

print(sum)

# looks like...
print(int(n**4/4 + n**3/2 + n**2/4))


########################
# sums of fourth powers

n = 1000
sum = 0
for i in range(1,n+1):
  sum += i**4

print(sum)

# looks like...
print(int(n**5/5 + n**4/2 + n**3/3 - n/30))


########################
# sums of fifth powers

n = 1000
sum = 0
for i in range(1,n+1):
  sum += i**5

print(sum)

# hard to eyeball it,
# but it probably starts with n^6/6 + n^5/2,
# so let's subtract that off

print(sum - int(n**6/6 + n**5/2))

# you're going to start running into rounding errors at
# this point, so maybe use this package for higher precision:
from decimal import Decimal
n = Decimal(1000)
print(sum - int(n**6/6 + n**5/2))

# or you could get greater precision
# by using fractions instead of decimals
from fractions import Fraction
n = Fraction(1000,1) # this is 1000/1
print(int(sum - (n**6/6 + n**5/2)))

