結果

問題 No.278 連続する整数の和(2)
ユーザー tentententen
提出日時 2020-10-05 09:42:32
言語 Java21
(openjdk 21)
結果
AC  
実行時間 142 ms / 2,000 ms
コード長 643 bytes
コンパイル時間 2,054 ms
コンパイル使用メモリ 71,144 KB
実行使用メモリ 56,328 KB
最終ジャッジ日時 2023-09-27 01:47:37
合計ジャッジ時間 5,276 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 121 ms
53,772 KB
testcase_01 AC 121 ms
55,472 KB
testcase_02 AC 136 ms
55,712 KB
testcase_03 AC 120 ms
55,460 KB
testcase_04 AC 121 ms
55,580 KB
testcase_05 AC 119 ms
54,020 KB
testcase_06 AC 120 ms
55,656 KB
testcase_07 AC 123 ms
55,504 KB
testcase_08 AC 137 ms
55,532 KB
testcase_09 AC 138 ms
55,708 KB
testcase_10 AC 142 ms
56,004 KB
testcase_11 AC 139 ms
55,608 KB
testcase_12 AC 119 ms
55,956 KB
testcase_13 AC 139 ms
56,328 KB
testcase_14 AC 133 ms
55,772 KB
testcase_15 AC 135 ms
55,476 KB
testcase_16 AC 136 ms
55,472 KB
testcase_17 AC 140 ms
55,728 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