Skip to main content
Code Review

Return to Revisions

2 of 2
added 121 characters in body

Seems trivial. Pair them, each pair is worth -1.

f(1000) = 1 - 2 + 3 - 4 + ... + 999 - 1000
 = (1 - 2) + (3 - 4) + ... + (999 - 1000)
 = -1 -1 + ... + -1
 = -500

Odd n left as exercise for the reader.

(I wrote this when the question title still said "1 − 2 + 3 − 4 + · · ·", can't be bothered to switch all signs now.)

default

AltStyle によって変換されたページ (->オリジナル) /