I am writing a code which returns something like 1^k + 2^k + 3^k......n-1 where k be any number.Below is my code.I am getting a memory error.How do I optimise it. Sample test case for wrong error:
1 10000000000000000 400
#!/bin/python
import sys
def highwayConstruction(n, k):
# Complete this function
sum=0
for i in range(1,n-1):
sum+=(n-i)**k
return sum
q = int(raw_input().strip())
print "Qw"
for a0 in xrange(q):
n, k = raw_input().strip().split(' ')
n, k = [long(n), int(k)]
result = highwayConstruction(n, k)
print result