Problem Description
Loading...
Problem Analysis
Input n m
Then there is an expression
Sum from 1 to n, with the sign changing every m numbers
For n=12, m=3:
-1 -2 -3 +4 +5 +6 -7 -8 -9 +10 +11 +12
For n=4, m=1:
-1 +2 -3 +4
What needs to be output is
the value of this expression
Computing it directly might be a bit troublesome
but we can look for a pattern
and find that the value of the expression
is exactly equal to $n*m/2$
This can be derived by manually working out several more cases
So the code becomes very simple~
cpp
| |
Problem link: 【Light】[1294]Positive Negative Sign