結果

問題 No.982 Add
ユーザー forest3
提出日時 2020-07-21 12:16:50
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 27 ms / 2,000 ms
コード長 470 bytes
コンパイル時間 3,195 ms
コンパイル使用メモリ 165,844 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-12-27 16:25:45
合計ジャッジ時間 3,085 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 23
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
 
int main()
{
	int A, B;
	cin >> A >> B;

	int gcd = __gcd( A, B );
	if( gcd != 1 ) {
		cout << -1 << endl;
		return 0;
	}
	auto f = [&]( int n ) -> bool
	{
		for( int x = 0; x * A <= n; x++ ) {
			for( int y = 0; y * B <= n; y++ ) {
				if( A * x + B * y == n ) return true;
			}
		}
		return false;
	};
	int ans = 0;
	for( int n = 1; n < 10000; n++ ) {
		if( f( n ) == false ) {
			ans++;
		}
	}

	cout << ans << endl;
}
0