結果

問題 No.278 連続する整数の和(2)
ユーザー tentententen
提出日時 2020-10-05 09:41:49
言語 Java19
(openjdk 21)
結果
WA  
実行時間 -
コード長 643 bytes
コンパイル時間 2,149 ms
コンパイル使用メモリ 71,392 KB
実行使用メモリ 56,072 KB
最終ジャッジ日時 2023-09-27 01:47:31
合計ジャッジ時間 5,836 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 127 ms
55,568 KB
testcase_01 WA -
testcase_02 AC 141 ms
56,028 KB
testcase_03 AC 125 ms
56,040 KB
testcase_04 AC 125 ms
56,016 KB
testcase_05 AC 128 ms
55,968 KB
testcase_06 AC 130 ms
55,640 KB
testcase_07 AC 126 ms
56,072 KB
testcase_08 AC 142 ms
55,676 KB
testcase_09 AC 143 ms
55,664 KB
testcase_10 AC 146 ms
55,776 KB
testcase_11 AC 145 ms
55,756 KB
testcase_12 AC 127 ms
55,732 KB
testcase_13 AC 141 ms
53,668 KB
testcase_14 AC 137 ms
55,764 KB
testcase_15 AC 137 ms
55,764 KB
testcase_16 AC 137 ms
55,592 KB
testcase_17 AC 142 ms
55,776 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long n = sc.nextLong();
        if (n == 1) {
            System.out.println(1);
            return;
        }
        long x;
        if (n % 2 == 0) {
            x = n / 2;
        } else {
            x = n;
        }
        long ans = 1 + x;
        for (long i = 2; i <= Math.sqrt(x); i++) {
            if (x % i == 0) {
                ans += i;
                if (i * i < x) {
                    ans += x / i;
                }
            }
        }
        System.out.println(ans);
    }
}
0