結果
| 問題 |
No.982 Add
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2020-02-11 13:38:21 |
| 言語 | C++17(clang) (17.0.6 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 2,000 ms |
| コード長 | 780 bytes |
| コンパイル時間 | 800 ms |
| コンパイル使用メモリ | 129,728 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-11-30 16:22:19 |
| 合計ジャッジ時間 | 1,786 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 23 |
ソースコード
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
template <class T>
T gcd(T n, T m) {
while (m != 0) {
n %= m;
std::swap(n, m);
}
return n;
}
void solve() {
int a, b;
std::cin >> a >> b;
if (gcd(a, b) > 1) {
std::cout << -1 << std::endl;
return;
}
int m = a * b * 2;
std::vector<bool> ok(m + 1, true);
for (int x = 0; a * x <= m; ++x) {
for (int y = 0; a * x + b * y <= m; ++y) {
ok[a * x + b * y] = false;
}
}
int ans = std::accumulate(ok.begin(), ok.end(), 0);
std::cout << ans << std::endl;
}
int main() {
std::cin.tie(nullptr);
std::cout.tie(nullptr);
std::ios::sync_with_stdio(false);
solve();
return 0;
}