結果

問題 No.141 魔法少女コバ
ユーザー kenkooookenkoooo
提出日時 2015-03-14 03:16:20
言語 Java21
(openjdk 21)
結果
AC  
実行時間 618 ms / 5,000 ms
コード長 1,002 bytes
コンパイル時間 2,000 ms
コンパイル使用メモリ 73,628 KB
実行使用メモリ 49,424 KB
最終ジャッジ日時 2023-09-11 08:19:21
合計ジャッジ時間 12,892 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 43 ms
48,984 KB
testcase_01 AC 616 ms
49,424 KB
testcase_02 AC 618 ms
49,416 KB
testcase_03 AC 42 ms
48,772 KB
testcase_04 AC 42 ms
48,932 KB
testcase_05 AC 42 ms
49,000 KB
testcase_06 AC 42 ms
48,852 KB
testcase_07 AC 42 ms
49,028 KB
testcase_08 AC 42 ms
48,984 KB
testcase_09 AC 42 ms
48,920 KB
testcase_10 AC 42 ms
48,980 KB
testcase_11 AC 42 ms
48,844 KB
testcase_12 AC 42 ms
48,636 KB
testcase_13 AC 43 ms
48,876 KB
testcase_14 AC 42 ms
48,856 KB
testcase_15 AC 41 ms
49,000 KB
testcase_16 AC 42 ms
48,928 KB
testcase_17 AC 42 ms
49,368 KB
testcase_18 AC 42 ms
49,132 KB
testcase_19 AC 42 ms
48,852 KB
testcase_20 AC 42 ms
48,992 KB
testcase_21 AC 42 ms
48,652 KB
testcase_22 AC 42 ms
49,132 KB
testcase_23 AC 41 ms
48,764 KB
testcase_24 AC 41 ms
49,000 KB
testcase_25 AC 42 ms
48,876 KB
testcase_26 AC 41 ms
48,868 KB
testcase_27 AC 42 ms
49,128 KB
testcase_28 AC 41 ms
48,968 KB
testcase_29 AC 41 ms
48,932 KB
testcase_30 AC 41 ms
48,836 KB
testcase_31 AC 42 ms
49,124 KB
testcase_32 AC 41 ms
48,992 KB
testcase_33 AC 43 ms
48,856 KB
testcase_34 AC 42 ms
48,972 KB
testcase_35 AC 42 ms
48,832 KB
testcase_36 AC 43 ms
48,948 KB
testcase_37 AC 43 ms
48,884 KB
testcase_38 AC 42 ms
48,932 KB
testcase_39 AC 41 ms
48,884 KB
testcase_40 AC 41 ms
48,956 KB
testcase_41 AC 42 ms
48,992 KB
testcase_42 AC 41 ms
48,776 KB
testcase_43 AC 42 ms
48,972 KB
testcase_44 AC 42 ms
48,656 KB
testcase_45 AC 42 ms
48,684 KB
testcase_46 AC 41 ms
48,928 KB
testcase_47 AC 41 ms
48,700 KB
testcase_48 AC 42 ms
49,020 KB
testcase_49 AC 42 ms
48,680 KB
testcase_50 AC 42 ms
48,936 KB
testcase_51 AC 42 ms
48,860 KB
testcase_52 AC 44 ms
49,272 KB
testcase_53 AC 42 ms
48,792 KB
testcase_54 AC 43 ms
48,860 KB
testcase_55 AC 42 ms
49,108 KB
testcase_56 AC 42 ms
48,644 KB
testcase_57 AC 42 ms
49,020 KB
testcase_58 AC 43 ms
48,684 KB
testcase_59 AC 43 ms
49,032 KB
testcase_60 AC 42 ms
49,092 KB
testcase_61 AC 42 ms
46,748 KB
testcase_62 AC 42 ms
46,704 KB
testcase_63 AC 42 ms
48,608 KB
testcase_64 AC 43 ms
48,780 KB
testcase_65 AC 43 ms
48,972 KB
testcase_66 AC 41 ms
48,860 KB
testcase_67 AC 43 ms
48,768 KB
testcase_68 AC 42 ms
48,872 KB
testcase_69 AC 43 ms
49,036 KB
testcase_70 AC 42 ms
48,876 KB
testcase_71 AC 43 ms
48,868 KB
testcase_72 AC 43 ms
48,928 KB
testcase_73 AC 41 ms
48,864 KB
testcase_74 AC 41 ms
48,992 KB
testcase_75 AC 42 ms
48,856 KB
testcase_76 AC 41 ms
48,856 KB
testcase_77 AC 42 ms
49,136 KB
testcase_78 AC 42 ms
48,856 KB
testcase_79 AC 42 ms
48,836 KB
testcase_80 AC 42 ms
48,884 KB
testcase_81 AC 42 ms
48,836 KB
testcase_82 AC 43 ms
49,004 KB
testcase-evil-0.txt AC 328 ms
49,180 KB
testcase-evil-1.txt AC 225 ms
49,328 KB
testcase-evil-2.txt AC 98 ms
49,264 KB
testcase-evil-3.txt AC 144 ms
47,452 KB
testcase-evil-4.txt AC 443 ms
49,264 KB
testcase-evil-5.txt AC 190 ms
49,264 KB
testcase-evil-6.txt AC 123 ms
49,388 KB
testcase-evil-7.txt AC 344 ms
49,320 KB
testcase-evil-8.txt AC 131 ms
49,616 KB
testcase-evil-9.txt AC 73 ms
49,392 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.IOException;

public class Main {

	public static void main(String[] args) {
		int M = nextInt();
		int N = nextInt();
		int gcd = gcd(M, N);
		M /= gcd;
		N /= gcd;

		int magic = 0;
		while (N != M || N != 1) {
			if (M < N) {
				int tmp = M;
				M = N;
				N = tmp;
			} else {
				M -= N;
			}
			magic++;
		}
		System.out.println(magic);

	}

	static int gcd(int a, int b) {
		// b=0ならaを最大公約数として終了
		if (b == 0) {
			return a;
		} else {
			// a÷bのあまりをb、元のbをaとして2.にもどる
			return gcd(b, a % b);
		}
	}

	static int nextInt() {
		int c;
		try {
			c = System.in.read();
			while (c != '-' && (c < '0' || c > '9'))
				c = System.in.read();
			if (c == '-')
				return -nextInt();
			int res = 0;
			while (c >= '0' && c <= '9') {
				res = res * 10 + c - '0';
				c = System.in.read();
			}
			return res;
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return -1;
	}

}
0