結果

問題 No.982 Add
ユーザー 37zigen37zigen
提出日時 2020-02-11 15:23:14
言語 Java19
(openjdk 19.0.1)
結果
AC  
実行時間 89 ms / 2,000 ms
コード長 555 bytes
コンパイル時間 1,497 ms
実行使用メモリ 37,732 KB
最終ジャッジ日時 2022-11-24 18:06:09
合計ジャッジ時間 5,082 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 79 ms
37,528 KB
testcase_01 AC 79 ms
37,316 KB
testcase_02 AC 79 ms
37,540 KB
testcase_03 AC 85 ms
37,600 KB
testcase_04 AC 84 ms
37,624 KB
testcase_05 AC 82 ms
37,620 KB
testcase_06 AC 78 ms
37,580 KB
testcase_07 AC 78 ms
37,560 KB
testcase_08 AC 81 ms
37,544 KB
testcase_09 AC 80 ms
37,704 KB
testcase_10 AC 86 ms
37,576 KB
testcase_11 AC 89 ms
37,732 KB
testcase_12 AC 83 ms
37,560 KB
testcase_13 AC 84 ms
37,504 KB
testcase_14 AC 87 ms
37,580 KB
testcase_15 AC 83 ms
37,424 KB
testcase_16 AC 85 ms
37,716 KB
testcase_17 AC 85 ms
37,612 KB
testcase_18 AC 87 ms
37,600 KB
testcase_19 AC 84 ms
37,608 KB
testcase_20 AC 84 ms
37,372 KB
testcase_21 AC 86 ms
37,316 KB
testcase_22 AC 87 ms
37,432 KB
testcase_23 AC 89 ms
37,640 KB
testcase_24 AC 84 ms
37,588 KB
testcase_25 AC 88 ms
37,624 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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);
	}
}
0