#P1992. Grandpa's Clear Path
Grandpa's Clear Path
Grandpa's Clear Path
In the quiet countryside, an elderly grandpa walks without wanting to wander in circles, because doing so makes him drowsy. One day, he meets Xia A, who, carrying a map and upholding the spirit of helpfulness, wonders whether the road conditions will keep him alert. Meanwhile, Xia A has some math homework for you.
You are given two integers, R and N. If R is even, compute the sum of the first N even numbers; if R is odd, compute the sum of the first N odd numbers.
The formulas are as follows:
- When R is even: \(S = N \times (N+1)\)
- When R is odd: \(S = N^2\)
inputFormat
The input consists of two space-separated integers: R and N.
outputFormat
Output a single integer according to the conditions provided.
sample
2 3
12