結果

問題 No.982 Add
ユーザー leaf_1415
提出日時 2020-02-11 13:35:29
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 137 ms / 2,000 ms
コード長 554 bytes
コンパイル時間 490 ms
コンパイル使用メモリ 59,644 KB
実行使用メモリ 6,820 KB
最終ジャッジ日時 2024-10-01 07:21:55
合計ジャッジ時間 2,524 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 23
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <set>
#define llint long long

using namespace std;

llint a, b;
bool used[2000005];

llint gcd(llint a, llint b)
{
	if(b == 0) return a;
	return gcd(b, a%b);
}

int main(void)
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	cin >> a >> b;
	if(gcd(a, b) > 1){
		cout << -1 << endl;
		return 0;
	}
	
	set<llint> S;
	for(int i = 0; i <= 10000; i++){
		for(int j = 0; j <= 10000; j++){
			used[a*i+b*j] = true;
		}
	}
	
	llint ans = 0;
	for(int i = 1; i < 10005; i++){
		if(!used[i]) ans++;
	}
	cout << ans << endl;
	
	
	return 0;
}
0