結果

問題 No.982 Add
ユーザー htensaihtensai
提出日時 2020-02-13 19:08:18
言語 Java21
(openjdk 21)
結果
AC  
実行時間 143 ms / 2,000 ms
コード長 734 bytes
コンパイル時間 2,195 ms
コンパイル使用メモリ 74,264 KB
実行使用メモリ 41,720 KB
最終ジャッジ日時 2024-04-15 23:18:48
合計ジャッジ時間 6,939 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 136 ms
41,368 KB
testcase_01 AC 137 ms
41,264 KB
testcase_02 AC 138 ms
41,400 KB
testcase_03 AC 141 ms
41,552 KB
testcase_04 AC 140 ms
41,344 KB
testcase_05 AC 138 ms
41,720 KB
testcase_06 AC 138 ms
41,596 KB
testcase_07 AC 138 ms
41,324 KB
testcase_08 AC 139 ms
41,432 KB
testcase_09 AC 141 ms
41,364 KB
testcase_10 AC 141 ms
41,380 KB
testcase_11 AC 139 ms
41,396 KB
testcase_12 AC 138 ms
41,616 KB
testcase_13 AC 142 ms
41,072 KB
testcase_14 AC 139 ms
41,060 KB
testcase_15 AC 138 ms
41,532 KB
testcase_16 AC 143 ms
41,476 KB
testcase_17 AC 125 ms
40,120 KB
testcase_18 AC 136 ms
41,336 KB
testcase_19 AC 138 ms
41,404 KB
testcase_20 AC 138 ms
41,380 KB
testcase_21 AC 137 ms
41,336 KB
testcase_22 AC 138 ms
41,260 KB
testcase_23 AC 137 ms
41,468 KB
testcase_24 AC 139 ms
41,340 KB
testcase_25 AC 140 ms
41,320 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		if (gcd(a, b) != 1) {
		    System.out.println(-1);
		    return;
		}
		int max = a * b;
		boolean[] check = new boolean[max + 1];
		for (int i = 0; i * a <= max; i++) {
		    for (int j = 0; i * a + j * b <= max; j++) {
		        check[i * a + j * b] = true;
		    }
		}
		int count = 0;
		for (int i = 1; i <= max; i++) {
		    if (!check[i]) {
		        count++;
		    }
		}
		System.out.println(count);
   }
   
   static int gcd(int x, int y) {
       if (x % y == 0) {
           return y;
       } else {
           return gcd(y, x % y);
       }
   }
}
0