project euler problem 6 https projecteuler netproblem6 sum square difference the sum of the squares of the first ten natural numbers is 12 22 102 385 the square of the sum of the first ten natural numbers is 1 2 102 552 3025 hence the difference between the sum of the squares of the first ten natural numbers and the square of the sum is 3025 385 2640 find the difference between the sum of the squares of the first one hundred natural numbers and the square of the sum returns the difference between the sum of the squares of the first n natural numbers and the square of the sum solution10 2640 solution15 13160 solution20 41230 solution50 1582700 returns the difference between the sum of the squares of the first n natural numbers and the square of the sum solution 10 2640 solution 15 13160 solution 20 41230 solution 50 1582700
def solution(n: int = 100) -> int:
    

    sum_of_squares = n * (n + 1) * (2 * n + 1) / 6
    square_of_sum = (n * (n + 1) / 2) ** 2
    return int(square_of_sum - sum_of_squares)


if __name__ == "__main__":
    print(f"{solution() = }")