結果

問題 No.278 連続する整数の和(2)
ユーザー htensaihtensai
提出日時 2020-01-09 11:42:09
言語 Java21
(openjdk 21)
結果
AC  
実行時間 65 ms / 2,000 ms
コード長 791 bytes
コンパイル時間 2,182 ms
コンパイル使用メモリ 73,040 KB
実行使用メモリ 50,272 KB
最終ジャッジ日時 2023-08-15 01:12:02
合計ジャッジ時間 4,127 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 42 ms
49,308 KB
testcase_01 AC 44 ms
49,328 KB
testcase_02 AC 61 ms
49,952 KB
testcase_03 AC 42 ms
49,220 KB
testcase_04 AC 42 ms
49,504 KB
testcase_05 AC 43 ms
49,708 KB
testcase_06 AC 44 ms
49,224 KB
testcase_07 AC 43 ms
49,316 KB
testcase_08 AC 62 ms
49,952 KB
testcase_09 AC 63 ms
49,984 KB
testcase_10 AC 65 ms
50,040 KB
testcase_11 AC 64 ms
50,272 KB
testcase_12 AC 42 ms
49,156 KB
testcase_13 AC 63 ms
50,016 KB
testcase_14 AC 57 ms
50,040 KB
testcase_15 AC 59 ms
50,044 KB
testcase_16 AC 59 ms
49,852 KB
testcase_17 AC 62 ms
50,048 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