結果

問題 No.278 連続する整数の和(2)
ユーザー tentententen
提出日時 2023-04-04 14:51:03
言語 Java21
(openjdk 21)
結果
AC  
実行時間 86 ms / 2,000 ms
コード長 2,034 bytes
コンパイル時間 2,583 ms
コンパイル使用メモリ 83,844 KB
実行使用メモリ 55,016 KB
最終ジャッジ日時 2024-04-08 14:29:47
合計ジャッジ時間 5,528 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 56 ms
53,944 KB
testcase_01 AC 54 ms
53,984 KB
testcase_02 AC 79 ms
54,888 KB
testcase_03 AC 59 ms
53,992 KB
testcase_04 AC 57 ms
53,996 KB
testcase_05 AC 60 ms
53,988 KB
testcase_06 AC 58 ms
53,984 KB
testcase_07 AC 57 ms
53,992 KB
testcase_08 AC 83 ms
54,900 KB
testcase_09 AC 77 ms
55,016 KB
testcase_10 AC 84 ms
54,784 KB
testcase_11 AC 85 ms
54,880 KB
testcase_12 AC 56 ms
51,908 KB
testcase_13 AC 86 ms
54,996 KB
testcase_14 AC 75 ms
54,756 KB
testcase_15 AC 79 ms
54,896 KB
testcase_16 AC 77 ms
55,004 KB
testcase_17 AC 80 ms
52,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner();
        long n = sc.nextLong();
        long a = n;
        long b = n - 1;
        if (a % 2 == 0) {
            a /= 2;
        } else {
            b /= 2;
        }
        long ans = 0;
        for (long i = 1; i <= Math.sqrt(n); i++) {
            if (n % i == 0) {
                if (a % i == 0 || b % i == 0) {
                    ans += i;
                }
                if (i * i < n) {
                    long x = n / i;
                    if (a % x == 0 || b % x == 0) {
                        ans += x;
                    }
                }
            }
        }
        System.out.println(ans);
    }
}
class Utilities {
    static String arrayToLineString(Object[] arr) {
        return Arrays.stream(arr).map(x -> x.toString()).collect(Collectors.joining("\n"));
    }
    
    static String arrayToLineString(int[] arr) {
        return String.join("\n", Arrays.stream(arr).mapToObj(String::valueOf).toArray(String[]::new));
    }
}
class Scanner {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    StringTokenizer st = new StringTokenizer("");
    StringBuilder sb = new StringBuilder();
    
    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 int[] nextIntArray() throws Exception {
        return Stream.of(br.readLine().split(" ")).mapToInt(Integer::parseInt).toArray();
    }
    
    public String next() throws Exception {
        while (!st.hasMoreTokens()) {
            st = new StringTokenizer(br.readLine());
        }
        return st.nextToken();
    }
    
}
0