Skip to content

Instantly share code, notes, and snippets.

@diunko
Created January 18, 2017 11:45
Show Gist options
  • Save diunko/cbac62d294429241eda78727f8b7cf55 to your computer and use it in GitHub Desktop.
Save diunko/cbac62d294429241eda78727f8b7cf55 to your computer and use it in GitHub Desktop.
import sys
def Sum(N):
S = 0
k = 1
while k <= N:
S = S + k
k = k + 1
return S
def Sum2(N):
return N*(N+1)//2
N, = [int(s) for s in sys.stdin.readline().strip().split()]
if N < 1:
r = -Sum(-N) + 1
print (r)
else:
r = Sum(N)
print (r)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment