結果

問題 No.276 連続する整数の和(1)
ユーザー htensaihtensai
提出日時 2019-12-23 18:30:09
言語 Java21
(openjdk 21)
結果
AC  
実行時間 129 ms / 1,000 ms
コード長 379 bytes
コンパイル時間 2,345 ms
コンパイル使用メモリ 74,256 KB
実行使用メモリ 57,692 KB
最終ジャッジ日時 2023-10-17 23:55:05
合計ジャッジ時間 4,711 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 127 ms
57,588 KB
testcase_01 AC 128 ms
57,692 KB
testcase_02 AC 129 ms
57,332 KB
testcase_03 AC 127 ms
57,552 KB
testcase_04 AC 128 ms
57,500 KB
testcase_05 AC 128 ms
57,580 KB
testcase_06 AC 129 ms
57,384 KB
testcase_07 AC 118 ms
56,240 KB
testcase_08 AC 126 ms
57,228 KB
testcase_09 AC 128 ms
57,456 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

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