結果
| 問題 |
No.982 Add
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2020-05-20 00:17:51 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 3 ms / 2,000 ms |
| コード長 | 924 bytes |
| コンパイル時間 | 1,774 ms |
| コンパイル使用メモリ | 169,628 KB |
| 実行使用メモリ | 6,824 KB |
| 最終ジャッジ日時 | 2024-10-01 23:21:07 |
| 合計ジャッジ時間 | 2,873 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 23 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr char newl = '\n';
// a * x + b * y == gcd(a, b) なるx, yを計算
// 返り値はgcd(a, b)
template<typename T>
T extgcd(T a, T b, T& x, T& y) {
T d = a;
if (b != 0) {
d = extgcd(b, a % b, y, x);
y -= (a / b) * x;
} else {
x = 1; y = 0;
}
return d;
}
int main() {
cin.tie(nullptr);
ios::sync_with_stdio(false);
int a, b;
cin >> a >> b;
if (__gcd(a, b) != 1) {
cout << -1 << newl;
return 0;
}
vector<int> dp(100001, false);
dp[0] = true;
for (int i = 0; i <= 100000; i++) {
if (!dp[i]) continue;
if (i + a <= 100000) dp[i + a] = true;
if (i + b <= 100000) dp[i + b] = true;
}
int ans = 0;
for (int i = 1; i <= 100000; i++) {
ans += !dp[i];
}
cout << ans << newl;
return 0;
}