結果
問題 | No.982 Add |
ユーザー |
|
提出日時 | 2020-02-15 16:10:02 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 7 ms / 2,000 ms |
コード長 | 558 bytes |
コンパイル時間 | 2,034 ms |
コンパイル使用メモリ | 192,624 KB |
最終ジャッジ日時 | 2025-01-09 00:50:02 |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 23 |
ソースコード
#define _USE_MATH_DEFINES #include <bits/stdc++.h> using namespace std; const int N = 1010100; bool dp[N]; signed main() { ios::sync_with_stdio(false); cin.tie(0); int a, b; cin >> a >> b; if (__gcd(a, b) != 1) { cout << -1 << endl; return 0; } dp[0] = true; for (int i = 1; i < N; i++) { if (i - a >= 0 && dp[i - a]) dp[i] = true; } for (int i = 0; i < N; i++) { if (i - b >= 0 && dp[i - b]) dp[i] = true; } int ans = 0; for (int i = 1; i < N; i++) { ans += (int) !dp[i]; } cout << ans << endl; return 0; }