結果

問題 No.141 魔法少女コバ
ユーザー chiho_miyako
提出日時 2015-04-20 11:49:28
言語 Java
(openjdk 23)
結果
AC  
実行時間 126 ms / 5,000 ms
コード長 849 bytes
コンパイル時間 2,333 ms
コンパイル使用メモリ 75,216 KB
実行使用メモリ 41,292 KB
最終ジャッジ日時 2024-07-04 17:45:43
合計ジャッジ時間 15,803 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 93
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner koko = new Scanner(System.in);
        int m = koko.nextInt();
        int n = koko.nextInt();
        int mm = m/gcd(m, n);
        int nn = n/gcd(m, n);
        long ans = keisan(mm, nn, 0);
        System.out.println(ans);
    }
    static int gcd(int a, int b){
        if(b==0){
            return a;
        }else{
            return gcd(b, a%b);
        }
    }
    static long keisan(int m, int n, long count){
        if(m==n){
            return count;
        }else if(n==1){
            return count+m-1;
        }
        else if(m>n){
            int amari=m%n;
            int a = (m-amari)/n;
            return keisan(amari, n, count+a);
        }else{
            return keisan(n, m, count+1);
        }
    }
}
0