結果

問題 No.415 ぴょん
ユーザー 41Toame41Toame
提出日時 2018-04-25 15:30:59
言語 Java21
(openjdk 21)
結果
AC  
実行時間 136 ms / 1,000 ms
コード長 635 bytes
コンパイル時間 4,057 ms
コンパイル使用メモリ 77,532 KB
実行使用メモリ 41,608 KB
最終ジャッジ日時 2024-04-29 11:52:38
合計ジャッジ時間 8,539 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 135 ms
41,308 KB
testcase_01 AC 135 ms
41,272 KB
testcase_02 AC 133 ms
41,032 KB
testcase_03 AC 132 ms
41,500 KB
testcase_04 AC 135 ms
41,268 KB
testcase_05 AC 134 ms
41,168 KB
testcase_06 AC 131 ms
41,176 KB
testcase_07 AC 133 ms
41,108 KB
testcase_08 AC 136 ms
41,072 KB
testcase_09 AC 134 ms
41,252 KB
testcase_10 AC 132 ms
41,356 KB
testcase_11 AC 133 ms
41,608 KB
testcase_12 AC 134 ms
41,252 KB
testcase_13 AC 131 ms
41,420 KB
testcase_14 AC 132 ms
41,092 KB
testcase_15 AC 131 ms
41,480 KB
testcase_16 AC 133 ms
41,464 KB
testcase_17 AC 132 ms
41,356 KB
testcase_18 AC 133 ms
41,312 KB
testcase_19 AC 132 ms
41,600 KB
testcase_20 AC 132 ms
41,392 KB
testcase_21 AC 132 ms
41,112 KB
testcase_22 AC 133 ms
41,548 KB
testcase_23 AC 134 ms
41,600 KB
testcase_24 AC 131 ms
41,568 KB
testcase_25 AC 133 ms
41,464 KB
testcase_26 AC 134 ms
41,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class T02 {
   
    static int gcd(int a, int b) {
        if ( b > a) return gcd(b, a);
        else if (b == 0) return a;
        else return gcd(b, a % b);
    }
    
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int D = sc.nextInt();
        if ( N / 2 < D) {
            D = N - D;
        }
        if (D == 0) {
            System.out.println(0);
        }
        else if (gcd(N, D) > 1) {
            System.out.println(N / gcd(N, D) - 1);
        } else {
            System.out.println(N - 1);
        }

    }

}
0