結果

問題 No.415 ぴょん
ユーザー htensai
提出日時 2020-05-07 16:04:32
言語 Java
(openjdk 23)
結果
AC  
実行時間 140 ms / 1,000 ms
コード長 455 bytes
コンパイル時間 2,084 ms
コンパイル使用メモリ 74,500 KB
実行使用メモリ 54,492 KB
最終ジャッジ日時 2024-07-03 09:26:30
合計ジャッジ時間 6,974 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 27
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

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