GCD of Odd and Even Sums
You are given an integer n. Your task is to compute the GCD (greatest common divisor) of two values:
sumOdd: the sum of the smallestnpositive odd numbers.sumEven: the sum of the smallestnpositive even numbers.
Return the GCD of sumOdd and sumEven.
Example 1
Input
n = 4Output
4The first 4 odd numbers sum to 16 and the first 4 even numbers sum to 20, so
GCD(16, 20) = 4.Example 2
Input
n = 5Output
5The first 5 odd numbers sum to 25 and the first 5 even numbers sum to 30, so
GCD(25, 30) = 5.Constraints
- 1 <= n <= 1000