結果
問題 | No.278 連続する整数の和(2) |
ユーザー |
![]() |
提出日時 | 2017-01-08 00:08:38 |
言語 | C++11 (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 17 ms / 2,000 ms |
コード長 | 917 bytes |
コンパイル時間 | 567 ms |
コンパイル使用メモリ | 67,048 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-12-23 09:12:54 |
合計ジャッジ時間 | 1,438 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 18 |
ソースコード
#include <algorithm>#include <iostream>#include <map>#include <queue>#include <set>#include <string>#include <vector>#define rep(i, n) for (int i = 0; i < (n); i++)#define rrep(i, n) for (int i = (n)-1; i >= 0; i--)using namespace std;typedef long long int lli;/** 係数がわかれば良い* sum suc(n) = (nx+n(n+1)/2)*/lli gcd(lli A, lli B){if (B > A)swap(A, B);if (A % B == 0)return B;elsereturn gcd(B, A % B);}lli sum_of_yakusuu(lli N){lli ans = 0;lli cnt = 1;while (cnt * cnt <= N) {if (N % cnt == 0)ans += cnt + N / cnt;if (N == cnt * cnt) {ans -= cnt;}cnt++;}return ans;}int main(){lli n;cin >> n;if (n & 1) {cout << sum_of_yakusuu(n) << endl;} else {cout << sum_of_yakusuu(n / 2 * gcd(2, (n + 1))) << endl;}}