結果

問題 No.276 連続する整数の和(1)
ユーザー tentententen
提出日時 2020-10-05 09:36:48
言語 Java21
(openjdk 21)
結果
AC  
実行時間 127 ms / 1,000 ms
コード長 414 bytes
コンパイル時間 2,783 ms
コンパイル使用メモリ 71,900 KB
実行使用メモリ 56,040 KB
最終ジャッジ日時 2023-09-27 01:47:08
合計ジャッジ時間 4,983 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 126 ms
54,028 KB
testcase_01 AC 125 ms
53,752 KB
testcase_02 AC 126 ms
55,908 KB
testcase_03 AC 126 ms
55,772 KB
testcase_04 AC 127 ms
53,968 KB
testcase_05 AC 127 ms
56,040 KB
testcase_06 AC 126 ms
55,680 KB
testcase_07 AC 126 ms
55,976 KB
testcase_08 AC 126 ms
55,852 KB
testcase_09 AC 126 ms
55,508 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        long x = getGCD(n, (long)n * (n + 1) / 2);
        System.out.println(x);
    }
    
    static long getGCD(long x, long y) {
        if (x % y == 0) {
            return y;
        } else {
            return getGCD(y, x % y);
        }
    }
}
0