3658. GCD of Odd and Even Sums Easy
1/**
2 * [3658] GCD of Odd and Even Sums
3 *
4 * You are given an integer n. Your task is to compute the GCD (greatest common divisor) of two values:
5 *
6 *
7 * sumOdd: the sum of the smallest n positive odd numbers.
8 *
9 *
10 * sumEven: the sum of the smallest n positive even numbers.
11 *
12 *
13 * Return the GCD of sumOdd and sumEven.
14 *
15 * <strong class="example">Example 1:
16 * <div class="example-block">
17 * Input: <span class="example-io">n = 4</span>
18 * Output: <span class="example-io">4</span>
19 * Explanation:
20 *
21 * Sum of the first 4 odd numbers sumOdd = 1 + 3 + 5 + 7 = 16
22 * Sum of the first 4 even numbers sumEven = 2 + 4 + 6 + 8 = 20
23 *
24 * Hence, GCD(sumOdd, sumEven) = GCD(16, 20) = 4.
25 * </div>
26 * <strong class="example">Example 2:
27 * <div class="example-block">
28 * Input: <span class="example-io">n = 5</span>
29 * Output: <span class="example-io">5</span>
30 * Explanation:
31 *
32 * Sum of the first 5 odd numbers sumOdd = 1 + 3 + 5 + 7 + 9 = 25
33 * Sum of the first 5 even numbers sumEven = 2 + 4 + 6 + 8 + 10 = 30
34 *
35 * Hence, GCD(sumOdd, sumEven) = GCD(25, 30) = 5.
36 * </div>
37 *
38 * Constraints:
39 *
40 * 1 <= n <= 1000
41 *
42 */
43pub struct Solution {}
44
45// problem: https://leetcode.com/problems/gcd-of-odd-and-even-sums/
46// discuss: https://leetcode.com/problems/gcd-of-odd-and-even-sums/discuss/?currentPage=1&orderBy=most_votes&query=
47
48// submission codes start here
49
50impl Solution {
51 pub fn gcd_of_odd_even_sums(n: i32) -> i32 {
52 0
53 }
54}
55
56// submission codes end
57
58#[cfg(test)]
59mod tests {
60 use super::*;
61
62 #[test]
63 fn test_3658() {
64 }
65}
66Back
© 2026 bowen.ge All Rights Reserved.