結果

問題 No.278 連続する整数の和(2)
ユーザー tentententen
提出日時 2021-11-11 08:23:41
言語 Java21
(openjdk 21)
結果
AC  
実行時間 75 ms / 2,000 ms
コード長 1,303 bytes
コンパイル時間 2,090 ms
コンパイル使用メモリ 77,560 KB
実行使用メモリ 51,096 KB
最終ジャッジ日時 2024-05-01 23:36:49
合計ジャッジ時間 3,878 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 48 ms
50,140 KB
testcase_01 AC 49 ms
50,100 KB
testcase_02 AC 73 ms
50,684 KB
testcase_03 AC 50 ms
50,232 KB
testcase_04 AC 48 ms
50,008 KB
testcase_05 AC 49 ms
50,272 KB
testcase_06 AC 52 ms
50,056 KB
testcase_07 AC 51 ms
50,104 KB
testcase_08 AC 72 ms
50,980 KB
testcase_09 AC 72 ms
50,904 KB
testcase_10 AC 75 ms
50,996 KB
testcase_11 AC 73 ms
50,948 KB
testcase_12 AC 50 ms
50,200 KB
testcase_13 AC 70 ms
51,096 KB
testcase_14 AC 65 ms
50,824 KB
testcase_15 AC 66 ms
50,972 KB
testcase_16 AC 68 ms
50,880 KB
testcase_17 AC 73 ms
50,960 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner();
        long n = sc.nextLong();
        if (n % 2 == 0) {
            n /= 2;
        }
        long ans = 0;
        for (long i = 1; i <= Math.sqrt(n); i++) {
            if (n % i == 0) {
                ans += i;
                if (i * i < n) {
                    ans += n / i;
                }
            }
        }
        System.out.println(ans);
    }
    
}
class Scanner {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    StringTokenizer st = new StringTokenizer("");
    
    public Scanner() throws Exception {
        
    }
    
    public int nextInt() throws Exception {
        return Integer.parseInt(next());
    }
    
    public long nextLong() throws Exception {
        return Long.parseLong(next());
    }
    
    public double nextDouble() throws Exception {
        return Double.parseDouble(next());
    }
    
    public String nextLine() throws Exception {
        return br.readLine();
    }
    
    public String next() throws Exception {
        if (!st.hasMoreTokens()) {
            st = new StringTokenizer(br.readLine());
        }
        return st.nextToken();
    }
}
0