문제 링크

요약

  • 쉬운 문제.

최종

class Solution {
	// AS: Arithmetic Sequence
	int getSumAS(int initial, int common_diff, int n) {
		return n * initial + common_diff * n * (n - 1) / 2;
	}
 
	int getGCD(int a, int b) {
		while (b) {
			int rem = a % b;
			a = b;
			b = rem;
		}
		return a;
	}
public:
	int gcdOfOddEvenSums(int n) {
		return getGCD(getSumAS(1, 2, n), getSumAS(2, 2, n));
	}
};