結果

問題 No.278 連続する整数の和(2)
ユーザー tentententen
提出日時 2021-11-11 08:23:41
言語 Java21
(openjdk 21)
結果
AC  
実行時間 65 ms / 2,000 ms
コード長 1,303 bytes
コンパイル時間 2,127 ms
コンパイル使用メモリ 73,712 KB
実行使用メモリ 50,952 KB
最終ジャッジ日時 2023-08-14 11:19:48
合計ジャッジ時間 4,099 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 43 ms
49,072 KB
testcase_01 AC 43 ms
48,976 KB
testcase_02 AC 63 ms
50,952 KB
testcase_03 AC 44 ms
49,412 KB
testcase_04 AC 43 ms
49,212 KB
testcase_05 AC 44 ms
49,196 KB
testcase_06 AC 45 ms
49,600 KB
testcase_07 AC 44 ms
49,592 KB
testcase_08 AC 62 ms
48,244 KB
testcase_09 AC 62 ms
49,460 KB
testcase_10 AC 65 ms
49,576 KB
testcase_11 AC 63 ms
49,708 KB
testcase_12 AC 43 ms
49,392 KB
testcase_13 AC 63 ms
50,080 KB
testcase_14 AC 58 ms
49,856 KB
testcase_15 AC 59 ms
49,524 KB
testcase_16 AC 57 ms
49,952 KB
testcase_17 AC 64 ms
49,548 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