結果

問題 No.982 Add
ユーザー 37zigen37zigen
提出日時 2020-02-11 15:23:14
言語 Java19
(openjdk 21)
結果
AC  
実行時間 128 ms / 2,000 ms
コード長 555 bytes
コンパイル時間 2,079 ms
コンパイル使用メモリ 71,524 KB
実行使用メモリ 56,344 KB
最終ジャッジ日時 2023-07-24 12:40:16
合計ジャッジ時間 6,882 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 126 ms
56,344 KB
testcase_01 AC 126 ms
55,508 KB
testcase_02 AC 126 ms
56,004 KB
testcase_03 AC 126 ms
55,536 KB
testcase_04 AC 128 ms
56,036 KB
testcase_05 AC 125 ms
55,840 KB
testcase_06 AC 126 ms
55,852 KB
testcase_07 AC 126 ms
56,104 KB
testcase_08 AC 126 ms
55,804 KB
testcase_09 AC 127 ms
55,932 KB
testcase_10 AC 127 ms
55,744 KB
testcase_11 AC 126 ms
55,400 KB
testcase_12 AC 126 ms
56,144 KB
testcase_13 AC 126 ms
55,536 KB
testcase_14 AC 127 ms
55,644 KB
testcase_15 AC 127 ms
55,496 KB
testcase_16 AC 126 ms
56,240 KB
testcase_17 AC 126 ms
55,684 KB
testcase_18 AC 128 ms
56,028 KB
testcase_19 AC 127 ms
55,912 KB
testcase_20 AC 126 ms
55,932 KB
testcase_21 AC 126 ms
55,676 KB
testcase_22 AC 126 ms
55,792 KB
testcase_23 AC 126 ms
54,084 KB
testcase_24 AC 128 ms
55,720 KB
testcase_25 AC 128 ms
55,732 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