結果

問題 No.982 Add
ユーザー ks2mks2m
提出日時 2020-02-11 13:44:28
言語 Java21
(openjdk 21)
結果
AC  
実行時間 140 ms / 2,000 ms
コード長 746 bytes
コンパイル時間 2,000 ms
コンパイル使用メモリ 75,424 KB
実行使用メモリ 58,076 KB
最終ジャッジ日時 2024-04-08 14:45:50
合計ジャッジ時間 6,251 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 131 ms
57,832 KB
testcase_01 AC 127 ms
57,588 KB
testcase_02 AC 126 ms
57,824 KB
testcase_03 AC 125 ms
57,836 KB
testcase_04 AC 129 ms
57,728 KB
testcase_05 AC 130 ms
57,708 KB
testcase_06 AC 129 ms
57,720 KB
testcase_07 AC 124 ms
57,828 KB
testcase_08 AC 129 ms
57,956 KB
testcase_09 AC 128 ms
57,720 KB
testcase_10 AC 130 ms
57,832 KB
testcase_11 AC 130 ms
57,828 KB
testcase_12 AC 129 ms
57,700 KB
testcase_13 AC 124 ms
57,704 KB
testcase_14 AC 126 ms
57,828 KB
testcase_15 AC 132 ms
57,952 KB
testcase_16 AC 137 ms
57,956 KB
testcase_17 AC 127 ms
57,820 KB
testcase_18 AC 129 ms
57,708 KB
testcase_19 AC 129 ms
57,700 KB
testcase_20 AC 127 ms
57,828 KB
testcase_21 AC 128 ms
58,076 KB
testcase_22 AC 129 ms
57,708 KB
testcase_23 AC 140 ms
57,844 KB
testcase_24 AC 132 ms
57,852 KB
testcase_25 AC 129 ms
57,568 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		sc.close();

		int c = Math.min(a, b);
		int d = Math.max(a, b);
		int end = a * b + d;
		int ans = 0;
		int cnt = 0;
		int i = 1;
		for ( ; i < end; i++) {
			if (can(i, c, d)) {
				cnt++;
			} else {
				ans++;
				cnt = 0;
			}
			if (cnt > d) {
				break;
			}
		}
		if (i == end) {
			System.out.println(-1);
		} else {
			System.out.println(ans);
		}
	}

	static boolean can(int x, int c, int d) {
		int end = x / d;
		for (int i = 0; i <= end; i++) {
			int r = x - (d * i);
			if (r % c == 0) {
				return true;
			}
		}
		return false;
	}
}
0