結果

問題 No.141 魔法少女コバ
ユーザー jp_ste
提出日時 2015-03-22 13:20:52
言語 Java
(openjdk 23)
結果
WA  
実行時間 -
コード長 691 bytes
コンパイル時間 2,105 ms
コンパイル使用メモリ 74,084 KB
実行使用メモリ 41,612 KB
最終ジャッジ日時 2024-06-29 00:02:33
合計ジャッジ時間 20,283 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 85 WA * 8
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		
		Scanner sc = new Scanner(System.in);
		int M = sc.nextInt();
		int N = sc.nextInt();
		
		int div = getCommonDivisor(M, N);
		int m = M/=div;
		int n = N/=div;
		int ans = 0;
	
		while(true) {
			if(m==1) break;
			
			if(m>n) {
				m-=n; 
				ans++;
			} else {
				int tmp=m;
				m=n;
				n=tmp;
				ans++;
			}
		}
		
		ans++; 
		ans += (n-1);
		System.out.println(ans);
	}
	
	static int getCommonDivisor(final int a, final int b) {
		
		int nowA = a;
		int nowB = b;
		
		while(true) {
			int tmp = nowB % nowA;
			if(tmp == 0) break;
			
			nowB = nowA;
			nowA = tmp;
		}
		return nowA;
	}
}
0