結果

問題 No.278 連続する整数の和(2)
ユーザー masamasa
提出日時 2015-11-12 19:53:58
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 451 bytes
コンパイル時間 384 ms
コンパイル使用メモリ 51,520 KB
実行使用メモリ 8,704 KB
最終ジャッジ日時 2023-10-11 15:43:35
合計ジャッジ時間 4,199 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,352 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 WA -
testcase_04 AC 1 ms
4,352 KB
testcase_05 AC 2 ms
4,352 KB
testcase_06 WA -
testcase_07 AC 2 ms
4,352 KB
testcase_08 TLE -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
権限があれば一括ダウンロードができます

ソースコード

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