結果

問題 No.415 ぴょん
ユーザー ym678ym678
提出日時 2016-08-27 22:18:52
言語 Java21
(openjdk 21)
結果
AC  
実行時間 132 ms / 1,000 ms
コード長 396 bytes
コンパイル時間 2,048 ms
コンパイル使用メモリ 74,372 KB
実行使用メモリ 41,716 KB
最終ジャッジ日時 2024-04-29 11:41:28
合計ジャッジ時間 6,496 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 117 ms
40,240 KB
testcase_01 AC 131 ms
41,084 KB
testcase_02 AC 131 ms
41,288 KB
testcase_03 AC 130 ms
41,076 KB
testcase_04 AC 129 ms
41,344 KB
testcase_05 AC 129 ms
41,128 KB
testcase_06 AC 116 ms
40,260 KB
testcase_07 AC 131 ms
41,256 KB
testcase_08 AC 128 ms
41,128 KB
testcase_09 AC 130 ms
41,148 KB
testcase_10 AC 126 ms
41,024 KB
testcase_11 AC 132 ms
41,300 KB
testcase_12 AC 131 ms
41,108 KB
testcase_13 AC 128 ms
41,172 KB
testcase_14 AC 130 ms
41,092 KB
testcase_15 AC 116 ms
39,772 KB
testcase_16 AC 129 ms
41,716 KB
testcase_17 AC 130 ms
41,452 KB
testcase_18 AC 117 ms
39,768 KB
testcase_19 AC 131 ms
41,512 KB
testcase_20 AC 129 ms
41,040 KB
testcase_21 AC 127 ms
40,936 KB
testcase_22 AC 131 ms
41,100 KB
testcase_23 AC 130 ms
41,180 KB
testcase_24 AC 126 ms
41,140 KB
testcase_25 AC 129 ms
41,488 KB
testcase_26 AC 114 ms
40,152 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long N = sc.nextLong();
		long D = sc.nextLong();
		if(N < D){
			long temp = N;
			N = D;
			D = temp;
		}
		System.out.println(N/gcd(N,D)-1);
	}
	public static long gcd(long N, long D){
		while(D != 0){
			long r = D;
			D = N % D;
			N = r;
		}
		return N;
	}
}
0