結果

問題 No.141 魔法少女コバ
ユーザー kenkooookenkoooo
提出日時 2015-03-14 03:22:32
言語 Java21
(openjdk 21)
結果
AC  
実行時間 46 ms / 5,000 ms
コード長 1,116 bytes
コンパイル時間 2,089 ms
コンパイル使用メモリ 73,572 KB
実行使用メモリ 49,368 KB
最終ジャッジ日時 2023-09-11 08:19:47
合計ジャッジ時間 9,050 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 44 ms
48,828 KB
testcase_01 AC 43 ms
48,860 KB
testcase_02 AC 44 ms
48,836 KB
testcase_03 AC 43 ms
48,924 KB
testcase_04 AC 43 ms
48,992 KB
testcase_05 AC 44 ms
48,944 KB
testcase_06 AC 43 ms
48,804 KB
testcase_07 AC 45 ms
48,916 KB
testcase_08 AC 44 ms
49,320 KB
testcase_09 AC 44 ms
48,848 KB
testcase_10 AC 43 ms
48,672 KB
testcase_11 AC 43 ms
48,848 KB
testcase_12 AC 43 ms
48,688 KB
testcase_13 AC 43 ms
48,868 KB
testcase_14 AC 43 ms
49,100 KB
testcase_15 AC 42 ms
48,808 KB
testcase_16 AC 43 ms
48,856 KB
testcase_17 AC 43 ms
48,776 KB
testcase_18 AC 43 ms
48,980 KB
testcase_19 AC 43 ms
48,948 KB
testcase_20 AC 43 ms
48,864 KB
testcase_21 AC 43 ms
48,876 KB
testcase_22 AC 43 ms
49,216 KB
testcase_23 AC 43 ms
48,840 KB
testcase_24 AC 43 ms
48,856 KB
testcase_25 AC 43 ms
49,024 KB
testcase_26 AC 42 ms
48,812 KB
testcase_27 AC 43 ms
48,924 KB
testcase_28 AC 42 ms
49,064 KB
testcase_29 AC 43 ms
48,836 KB
testcase_30 AC 42 ms
48,988 KB
testcase_31 AC 42 ms
48,848 KB
testcase_32 AC 42 ms
48,996 KB
testcase_33 AC 42 ms
49,012 KB
testcase_34 AC 43 ms
48,984 KB
testcase_35 AC 42 ms
48,852 KB
testcase_36 AC 43 ms
48,648 KB
testcase_37 AC 43 ms
49,048 KB
testcase_38 AC 44 ms
48,820 KB
testcase_39 AC 43 ms
48,848 KB
testcase_40 AC 44 ms
48,784 KB
testcase_41 AC 43 ms
49,108 KB
testcase_42 AC 43 ms
48,848 KB
testcase_43 AC 43 ms
46,932 KB
testcase_44 AC 44 ms
48,792 KB
testcase_45 AC 43 ms
47,388 KB
testcase_46 AC 45 ms
48,652 KB
testcase_47 AC 44 ms
48,644 KB
testcase_48 AC 44 ms
48,928 KB
testcase_49 AC 45 ms
48,928 KB
testcase_50 AC 44 ms
49,152 KB
testcase_51 AC 44 ms
48,936 KB
testcase_52 AC 44 ms
48,928 KB
testcase_53 AC 45 ms
49,028 KB
testcase_54 AC 44 ms
48,676 KB
testcase_55 AC 43 ms
48,780 KB
testcase_56 AC 44 ms
48,836 KB
testcase_57 AC 43 ms
49,368 KB
testcase_58 AC 43 ms
48,984 KB
testcase_59 AC 43 ms
48,940 KB
testcase_60 AC 43 ms
48,948 KB
testcase_61 AC 44 ms
48,800 KB
testcase_62 AC 44 ms
48,968 KB
testcase_63 AC 43 ms
48,856 KB
testcase_64 AC 42 ms
47,236 KB
testcase_65 AC 42 ms
49,168 KB
testcase_66 AC 42 ms
48,788 KB
testcase_67 AC 43 ms
49,100 KB
testcase_68 AC 43 ms
48,836 KB
testcase_69 AC 42 ms
48,840 KB
testcase_70 AC 42 ms
48,856 KB
testcase_71 AC 42 ms
48,992 KB
testcase_72 AC 42 ms
48,840 KB
testcase_73 AC 43 ms
46,880 KB
testcase_74 AC 42 ms
49,124 KB
testcase_75 AC 42 ms
48,864 KB
testcase_76 AC 43 ms
48,828 KB
testcase_77 AC 43 ms
48,848 KB
testcase_78 AC 46 ms
48,976 KB
testcase_79 AC 44 ms
48,948 KB
testcase_80 AC 42 ms
48,992 KB
testcase_81 AC 42 ms
48,984 KB
testcase_82 AC 43 ms
48,784 KB
testcase-evil-0.txt AC 43 ms
48,776 KB
testcase-evil-1.txt AC 43 ms
49,160 KB
testcase-evil-2.txt AC 42 ms
48,604 KB
testcase-evil-3.txt AC 43 ms
48,868 KB
testcase-evil-4.txt AC 42 ms
48,808 KB
testcase-evil-5.txt AC 43 ms
48,996 KB
testcase-evil-6.txt AC 42 ms
48,636 KB
testcase-evil-7.txt AC 43 ms
48,944 KB
testcase-evil-8.txt AC 43 ms
48,948 KB
testcase-evil-9.txt AC 43 ms
48,700 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;
				magic++;
			} else if (M % N == 0) {
				int p = M / N;
				magic += p - 1;
				M = N;
			} else {
				int p = M / N;
				M %= N;
				magic += p;
			}
		}
		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