結果

問題 No.982 Add
ユーザー ks2mks2m
提出日時 2020-02-11 13:44:28
言語 Java17
(openjdk 17.0.1)
結果
AC  
実行時間 88 ms / 2,000 ms
コード長 746 bytes
コンパイル時間 2,002 ms
使用メモリ 37,744 KB
最終ジャッジ日時 2022-11-24 17:25:18
合計ジャッジ時間 5,388 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
使用メモリ
testcase_00 AC 82 ms
37,524 KB
testcase_01 AC 80 ms
37,612 KB
testcase_02 AC 80 ms
37,320 KB
testcase_03 AC 79 ms
37,464 KB
testcase_04 AC 78 ms
37,272 KB
testcase_05 AC 80 ms
37,224 KB
testcase_06 AC 78 ms
37,432 KB
testcase_07 AC 77 ms
37,356 KB
testcase_08 AC 87 ms
37,348 KB
testcase_09 AC 85 ms
37,676 KB
testcase_10 AC 81 ms
37,420 KB
testcase_11 AC 79 ms
37,488 KB
testcase_12 AC 76 ms
37,320 KB
testcase_13 AC 80 ms
37,424 KB
testcase_14 AC 85 ms
37,504 KB
testcase_15 AC 78 ms
37,340 KB
testcase_16 AC 81 ms
37,328 KB
testcase_17 AC 78 ms
37,236 KB
testcase_18 AC 86 ms
37,428 KB
testcase_19 AC 80 ms
37,504 KB
testcase_20 AC 79 ms
37,412 KB
testcase_21 AC 79 ms
37,412 KB
testcase_22 AC 80 ms
37,324 KB
testcase_23 AC 85 ms
37,672 KB
testcase_24 AC 85 ms
37,744 KB
testcase_25 AC 88 ms
37,616 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