結果

問題 No.278 連続する整数の和(2)
ユーザー htensaihtensai
提出日時 2020-01-09 11:42:09
言語 Java21
(openjdk 21)
結果
AC  
実行時間 68 ms / 2,000 ms
コード長 791 bytes
コンパイル時間 2,311 ms
コンパイル使用メモリ 74,444 KB
実行使用メモリ 37,932 KB
最終ジャッジ日時 2024-05-02 13:38:58
合計ジャッジ時間 3,727 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 43 ms
36,820 KB
testcase_01 AC 43 ms
36,784 KB
testcase_02 AC 67 ms
37,564 KB
testcase_03 AC 43 ms
36,912 KB
testcase_04 AC 42 ms
37,076 KB
testcase_05 AC 43 ms
36,976 KB
testcase_06 AC 44 ms
36,564 KB
testcase_07 AC 45 ms
36,588 KB
testcase_08 AC 66 ms
37,904 KB
testcase_09 AC 66 ms
37,708 KB
testcase_10 AC 68 ms
37,736 KB
testcase_11 AC 68 ms
37,852 KB
testcase_12 AC 43 ms
36,940 KB
testcase_13 AC 64 ms
37,744 KB
testcase_14 AC 61 ms
37,740 KB
testcase_15 AC 63 ms
37,932 KB
testcase_16 AC 59 ms
37,588 KB
testcase_17 AC 65 ms
37,784 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;
import java.io.*;

public class Main {
    public static void main(String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        long n = Long.parseLong(br.readLine());
        long g;
        if (n % 2 == 0) {
            g = n / 2;
        } else {
            g = n;
        }
        long ans;
        if (g == 1) {
            ans = 1;
        } else {
            ans = g + 1;
        }
        for (long i = 2; i <= Math.sqrt(g); i++) {
            if (g % i == 0) {
                if (i * i == g) {
                    ans += i;
                } else {
                    ans += i;
                    ans += g / i;
                }
            }
        }
        System.out.println(ans);
    }
}
0