結果

問題 No.276 連続する整数の和(1)
ユーザー kkslucy1
提出日時 2018-03-13 00:58:55
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 2 ms / 1,000 ms
コード長 395 bytes
コンパイル時間 1,710 ms
コンパイル使用メモリ 159,468 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-11-15 21:43:25
合計ジャッジ時間 1,671 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 10
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

ll gcd(ll n, ll m) {
	if (n < m) {
		ll c = n;
		n = m;
		m = c;
	}
	if (m == 0) {
		return n;
	}
	if (n%m == 0) {
		return m;
	}
	else {
		return gcd(m, n%m);
	}
}

int main() {
	ll n;
	cin >> n;
	ll sum;
	if (n % 2 == 0) {
		sum = (n - 1)*(n / 2);
	}
	else {
		sum = (n / 2)*n;
	}
	cout << gcd(n, sum) << endl;

	return 0;
}
0