[LeetCode] GCD of Odd and Even Sums

3658. 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 first n odd numbers.
  • sumEven: the sum of the first n even numbers.

Return the GCD of sumOdd and sumEven.

1
2
3
4
5
6
class Solution {
public:
long long gcdOfOddEvenSums(long long n) {
return n;
}
};
Author: Song Hayoung
Link: https://songhayoung.github.io/2025/08/25/PS/LeetCode/gcd-of-odd-and-even-sums/
Copyright Notice: All articles in this blog are licensed under CC BY-NC-SA 4.0 unless stating additionally.