結果

問題 No.278 連続する整数の和(2)
ユーザー masa
提出日時 2015-11-12 19:53:58
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
WA  
実行時間 -
コード長 451 bytes
コンパイル時間 591 ms
コンパイル使用メモリ 55,600 KB
実行使用メモリ 13,760 KB
最終ジャッジ日時 2024-09-13 14:31:06
合計ジャッジ時間 4,015 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 6 WA * 2 TLE * 1 -- * 9
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <cstdio>

using namespace std;

int main() {
	long long n, ans = 0;

	cin >> n;
	// sum = k + (k + 1) + (k + 2) + ... + (k + (n - 1))
	//     = nk + n(n - 1)/2
	//     = n(k + (n - 1)/2 )

	if (n % 2 == 1) {
		ans = 1 + n;
	} else {
		long long m = n / 2;
		for (int i = 1; i*i <= m; i++) {
			if (m % i == 0) {
				ans += i + m / i;
				if (i*i == m) {
					ans -= i;
				}
			}
		}
	}
	cout << ans << endl;
	return 0;
}
0