Created
August 26, 2020 17:32
-
-
Save noel-yap/ad9e11d25bb89931eab66c8bcea2d508 to your computer and use it in GitHub Desktop.
Sum square difference: https://projecteuler.net/problem=6
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python3 | |
import argparse | |
def sum_of_sequence(n): | |
return n * (n + 1) / 2 | |
def sum_of_squares_of_sequence(n): | |
return n * (n + 1) * (2 * n + 1) / 6 | |
parser = argparse.ArgumentParser(description='Difference between sum of squares and square of sum.') | |
parser.add_argument('n') | |
args = parser.parse_args() | |
n = int(args.n) | |
print(sum_of_sequence(n) ** 2 - sum_of_squares_of_sequence(n)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment