結果

問題 No.982 Add
ユーザー 37zigen37zigen
提出日時 2020-02-11 15:23:14
言語 Java21
(openjdk 21)
結果
AC  
実行時間 135 ms / 2,000 ms
コード長 555 bytes
コンパイル時間 1,959 ms
コンパイル使用メモリ 74,024 KB
実行使用メモリ 58,092 KB
最終ジャッジ日時 2024-04-08 15:22:18
合計ジャッジ時間 6,622 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 125 ms
57,812 KB
testcase_01 AC 125 ms
58,092 KB
testcase_02 AC 123 ms
57,828 KB
testcase_03 AC 127 ms
57,820 KB
testcase_04 AC 128 ms
57,700 KB
testcase_05 AC 125 ms
57,836 KB
testcase_06 AC 125 ms
57,680 KB
testcase_07 AC 129 ms
57,836 KB
testcase_08 AC 128 ms
57,848 KB
testcase_09 AC 127 ms
57,844 KB
testcase_10 AC 129 ms
57,836 KB
testcase_11 AC 129 ms
57,828 KB
testcase_12 AC 119 ms
56,028 KB
testcase_13 AC 132 ms
57,848 KB
testcase_14 AC 126 ms
57,848 KB
testcase_15 AC 128 ms
57,848 KB
testcase_16 AC 130 ms
57,720 KB
testcase_17 AC 132 ms
57,852 KB
testcase_18 AC 131 ms
57,832 KB
testcase_19 AC 131 ms
57,712 KB
testcase_20 AC 133 ms
56,268 KB
testcase_21 AC 132 ms
58,076 KB
testcase_22 AC 132 ms
57,844 KB
testcase_23 AC 135 ms
57,948 KB
testcase_24 AC 133 ms
58,072 KB
testcase_25 AC 133 ms
55,740 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