結果

問題 No.141 魔法少女コバ
ユーザー tutuztutuz
提出日時 2018-09-14 22:06:20
言語 Java21
(openjdk 21)
結果
AC  
実行時間 47 ms / 5,000 ms
コード長 3,213 bytes
コンパイル時間 2,300 ms
コンパイル使用メモリ 74,604 KB
実行使用メモリ 50,160 KB
最終ジャッジ日時 2023-09-20 15:33:38
合計ジャッジ時間 11,293 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 45 ms
47,504 KB
testcase_01 AC 46 ms
49,576 KB
testcase_02 AC 45 ms
49,824 KB
testcase_03 AC 45 ms
49,452 KB
testcase_04 AC 45 ms
49,448 KB
testcase_05 AC 45 ms
49,644 KB
testcase_06 AC 45 ms
49,552 KB
testcase_07 AC 45 ms
49,632 KB
testcase_08 AC 45 ms
49,920 KB
testcase_09 AC 45 ms
49,608 KB
testcase_10 AC 45 ms
49,544 KB
testcase_11 AC 45 ms
49,444 KB
testcase_12 AC 46 ms
49,444 KB
testcase_13 AC 45 ms
49,496 KB
testcase_14 AC 45 ms
49,408 KB
testcase_15 AC 45 ms
49,444 KB
testcase_16 AC 46 ms
50,056 KB
testcase_17 AC 45 ms
49,904 KB
testcase_18 AC 45 ms
49,824 KB
testcase_19 AC 45 ms
49,500 KB
testcase_20 AC 45 ms
49,616 KB
testcase_21 AC 46 ms
49,748 KB
testcase_22 AC 46 ms
49,436 KB
testcase_23 AC 45 ms
49,408 KB
testcase_24 AC 45 ms
49,536 KB
testcase_25 AC 46 ms
50,040 KB
testcase_26 AC 46 ms
49,568 KB
testcase_27 AC 45 ms
49,600 KB
testcase_28 AC 45 ms
49,624 KB
testcase_29 AC 45 ms
49,804 KB
testcase_30 AC 45 ms
49,548 KB
testcase_31 AC 46 ms
49,500 KB
testcase_32 AC 45 ms
49,652 KB
testcase_33 AC 47 ms
49,456 KB
testcase_34 AC 45 ms
49,448 KB
testcase_35 AC 46 ms
49,556 KB
testcase_36 AC 46 ms
49,588 KB
testcase_37 AC 45 ms
49,636 KB
testcase_38 AC 46 ms
49,580 KB
testcase_39 AC 44 ms
49,484 KB
testcase_40 AC 45 ms
49,572 KB
testcase_41 AC 44 ms
49,456 KB
testcase_42 AC 45 ms
49,644 KB
testcase_43 AC 44 ms
49,404 KB
testcase_44 AC 45 ms
49,516 KB
testcase_45 AC 45 ms
49,464 KB
testcase_46 AC 45 ms
49,452 KB
testcase_47 AC 45 ms
49,468 KB
testcase_48 AC 44 ms
49,548 KB
testcase_49 AC 46 ms
49,640 KB
testcase_50 AC 45 ms
49,564 KB
testcase_51 AC 45 ms
49,636 KB
testcase_52 AC 45 ms
49,904 KB
testcase_53 AC 45 ms
49,544 KB
testcase_54 AC 45 ms
49,624 KB
testcase_55 AC 45 ms
47,856 KB
testcase_56 AC 44 ms
50,160 KB
testcase_57 AC 45 ms
49,412 KB
testcase_58 AC 45 ms
49,448 KB
testcase_59 AC 45 ms
49,596 KB
testcase_60 AC 46 ms
49,628 KB
testcase_61 AC 45 ms
49,548 KB
testcase_62 AC 45 ms
49,664 KB
testcase_63 AC 46 ms
49,704 KB
testcase_64 AC 45 ms
49,400 KB
testcase_65 AC 45 ms
49,556 KB
testcase_66 AC 45 ms
49,696 KB
testcase_67 AC 45 ms
49,704 KB
testcase_68 AC 45 ms
49,568 KB
testcase_69 AC 45 ms
49,512 KB
testcase_70 AC 45 ms
49,604 KB
testcase_71 AC 45 ms
49,640 KB
testcase_72 AC 45 ms
49,408 KB
testcase_73 AC 45 ms
49,448 KB
testcase_74 AC 45 ms
49,448 KB
testcase_75 AC 46 ms
50,052 KB
testcase_76 AC 45 ms
49,632 KB
testcase_77 AC 45 ms
49,396 KB
testcase_78 AC 44 ms
49,464 KB
testcase_79 AC 45 ms
49,536 KB
testcase_80 AC 45 ms
49,408 KB
testcase_81 AC 47 ms
49,580 KB
testcase_82 AC 45 ms
49,560 KB
testcase-evil-0.txt AC 45 ms
49,548 KB
testcase-evil-1.txt AC 45 ms
49,676 KB
testcase-evil-2.txt AC 45 ms
49,744 KB
testcase-evil-3.txt AC 45 ms
49,572 KB
testcase-evil-4.txt AC 45 ms
49,832 KB
testcase-evil-5.txt AC 46 ms
49,496 KB
testcase-evil-6.txt AC 46 ms
49,500 KB
testcase-evil-7.txt AC 45 ms
49,652 KB
testcase-evil-8.txt AC 45 ms
49,648 KB
testcase-evil-9.txt AC 45 ms
49,632 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.util.StringTokenizer;

public class Main {

	public static void main(String[] args) throws IOException {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		TaskX solver = new TaskX();
		solver.solve(1, in, out);
		out.close();
	}

	static int INF = 1 << 30;
	static long LINF = 1L << 55;
	static int MOD = 1000000007;
	static int[] mh4 = { 0, -1, 1, 0 };
	static int[] mw4 = { -1, 0, 0, 1 };
	static int[] mh8 = { -1, -1, -1, 0, 0, 1, 1, 1 };
	static int[] mw8 = { -1, 0, 1, -1, 1, -1, 0, 1 };

	static class TaskX {

		public void solve(int testNumber, InputReader in, PrintWriter out) {

			long m = in.nextLong(), n = in.nextLong();
			long g = gcd(n, m);
			m /= g;
			n /= g;

			long ans = f(m, n, 0);
			out.println(ans);

		}

		long f(long bs, long bb, long cnt) {

			long ret = 0;
			if (bb == bs) {
				return cnt;
			}
			if (bs - bb > 0) {
				ret += f(bs - bs/(bb+1)*bb, bb, cnt+bs/(bb+1));
			} else {
				ret += f(bb, bs, cnt+1);
			}

			return ret;
		}
	}

	public static long gcd(long a, long b) {
		return (b == 0) ? a : gcd(b, a % b);
	}

	static class InputReader {
		BufferedReader in;
		StringTokenizer tok;

		public String nextString() {
			while (!tok.hasMoreTokens()) {
				try {
					tok = new StringTokenizer(in.readLine(), " ");
				} catch (IOException e) {
					throw new InputMismatchException();
				}
			}
			return tok.nextToken();
		}

		public int nextInt() {
			return Integer.parseInt(nextString());
		}

		public long nextLong() {
			return Long.parseLong(nextString());
		}

		public double nextDouble() {
			return Double.parseDouble(nextString());
		}

		public int[] nextIntArray(int n) {
			int[] res = new int[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextInt();
			}
			return res;
		}

		public int[] nextIntArrayDec(int n) {
			int[] res = new int[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextInt() - 1;
			}
			return res;
		}

		public int[] nextIntArray1Index(int n) {
			int[] res = new int[n + 1];
			for (int i = 0; i < n; i++) {
				res[i + 1] = nextInt();
			}
			return res;
		}

		public long[] nextLongArray(int n) {
			long[] res = new long[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextLong();
			}
			return res;
		}

		public long[] nextLongArrayDec(int n) {
			long[] res = new long[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextLong() - 1;
			}
			return res;
		}

		public long[] nextLongArray1Index(int n) {
			long[] res = new long[n + 1];
			for (int i = 0; i < n; i++) {
				res[i + 1] = nextLong();
			}
			return res;
		}

		public double[] nextDoubleArray(int n) {
			double[] res = new double[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextDouble();
			}
			return res;
		}

		public InputReader(InputStream inputStream) {
			in = new BufferedReader(new InputStreamReader(inputStream));
			tok = new StringTokenizer("");
		}
	}

}
0