結果
| 問題 |
No.982 Add
|
| コンテスト | |
| ユーザー |
htensai
|
| 提出日時 | 2020-02-13 19:08:18 |
| 言語 | Java (openjdk 23) |
| 結果 |
AC
|
| 実行時間 | 132 ms / 2,000 ms |
| コード長 | 734 bytes |
| コンパイル時間 | 2,215 ms |
| コンパイル使用メモリ | 74,316 KB |
| 実行使用メモリ | 41,368 KB |
| 最終ジャッジ日時 | 2024-10-06 06:19:18 |
| 合計ジャッジ時間 | 6,594 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 23 |
ソースコード
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);
}
}
}
htensai