You are viewing a single comment's thread. Return to all comments →
Here's my solution:
record = {1:1} def sumOfFirstNNumbersSquared(n): if n in record: return record[n] else: record[n] = sumOfFirstNNumbersSquared(n - 1) + n ** 2 return record[n] t = int(input().strip()) for a0 in range(t): n = int(input().strip()) a = ( n * (n + 1) / 2 ) ** 2 b = sumOfFirstNNumbersSquared(n) print(int( abs(a - b)) )
Seems like cookies are disabled on this browser, please enable them to open this website
Project Euler #6: Sum square difference
You are viewing a single comment's thread. Return to all comments →
Here's my solution: