結果

問題 No.278 連続する整数の和(2)
ユーザー tentententen
提出日時 2020-10-05 09:42:32
言語 Java17
(openjdk 17.0.1)
結果
AC  
実行時間 126 ms / 2,000 ms
コード長 643 bytes
コンパイル時間 1,776 ms
使用メモリ 40,876 KB
最終ジャッジ日時 2023-02-18 06:14:45
合計ジャッジ時間 5,081 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
使用メモリ
testcase_00 AC 103 ms
40,352 KB
testcase_01 AC 101 ms
38,124 KB
testcase_02 AC 126 ms
38,804 KB
testcase_03 AC 99 ms
38,096 KB
testcase_04 AC 101 ms
38,232 KB
testcase_05 AC 103 ms
40,364 KB
testcase_06 AC 102 ms
37,464 KB
testcase_07 AC 103 ms
40,228 KB
testcase_08 AC 120 ms
38,888 KB
testcase_09 AC 124 ms
38,760 KB
testcase_10 AC 123 ms
38,520 KB
testcase_11 AC 123 ms
40,668 KB
testcase_12 AC 101 ms
38,324 KB
testcase_13 AC 125 ms
40,876 KB
testcase_14 AC 118 ms
40,540 KB
testcase_15 AC 119 ms
40,416 KB
testcase_16 AC 120 ms
40,636 KB
testcase_17 AC 126 ms
38,696 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 <= 2) {
            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