結果
| 問題 |
No.982 Add
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2020-02-11 15:23:14 |
| 言語 | Java (openjdk 23) |
| 結果 |
AC
|
| 実行時間 | 113 ms / 2,000 ms |
| コード長 | 555 bytes |
| コンパイル時間 | 1,729 ms |
| コンパイル使用メモリ | 73,816 KB |
| 実行使用メモリ | 41,644 KB |
| 最終ジャッジ日時 | 2024-10-01 07:53:50 |
| 合計ジャッジ時間 | 5,258 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 23 |
ソースコード
import java.util.Scanner;
class Main{
public static void main(String[] args) {
new Main().run();
}
void run() {
Scanner sc=new Scanner(System.in);
int A=sc.nextInt();
int B=sc.nextInt();
if(gcd(A,B)!=1) {
System.out.println(-1);
}else {
boolean[] ok=new boolean[100000];
for(int x=0;x<=2*B;++x) {
for(int y=0;y<=2*A;++y) {
ok[A*x+B*y]=true;
}
}
int ans=0;
for(int i=0;i<=2*A*B;++i) {
if(!ok[i])++ans;
}
System.out.println(ans);
}
}
int gcd(int a,int b) {
return a==0?b:gcd(b%a,a);
}
}