結果

問題 No.415 ぴょん
ユーザー takeya_okinotakeya_okino
提出日時 2017-07-09 11:23:49
言語 Java21
(openjdk 21)
結果
AC  
実行時間 139 ms / 1,000 ms
コード長 402 bytes
コンパイル時間 2,107 ms
コンパイル使用メモリ 74,180 KB
実行使用メモリ 41,592 KB
最終ジャッジ日時 2024-04-29 11:49:40
合計ジャッジ時間 6,703 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 116 ms
39,780 KB
testcase_01 AC 135 ms
41,276 KB
testcase_02 AC 135 ms
41,124 KB
testcase_03 AC 130 ms
41,164 KB
testcase_04 AC 130 ms
40,652 KB
testcase_05 AC 131 ms
41,092 KB
testcase_06 AC 134 ms
41,460 KB
testcase_07 AC 135 ms
41,480 KB
testcase_08 AC 135 ms
41,328 KB
testcase_09 AC 135 ms
41,192 KB
testcase_10 AC 120 ms
39,864 KB
testcase_11 AC 133 ms
41,208 KB
testcase_12 AC 136 ms
41,300 KB
testcase_13 AC 129 ms
41,124 KB
testcase_14 AC 135 ms
41,060 KB
testcase_15 AC 136 ms
40,976 KB
testcase_16 AC 136 ms
41,364 KB
testcase_17 AC 134 ms
41,152 KB
testcase_18 AC 135 ms
41,048 KB
testcase_19 AC 139 ms
41,436 KB
testcase_20 AC 135 ms
41,592 KB
testcase_21 AC 135 ms
41,220 KB
testcase_22 AC 135 ms
41,200 KB
testcase_23 AC 120 ms
39,792 KB
testcase_24 AC 134 ms
41,200 KB
testcase_25 AC 135 ms
40,888 KB
testcase_26 AC 134 ms
40,996 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    long N = sc.nextLong();
    long D = sc.nextLong();
    long g = gcd(N, D);
    System.out.println(N / g - 1);
  }

  public static long gcd(long a, long b) {
    if(b == 0) return a;
    long M = Math.max(a, b);
    long m = Math.min(a, b);
    return gcd(m, M % m);
  }
}
0