結果
問題 | No.982 Add |
ユーザー |
|
提出日時 | 2020-02-11 14:12:47 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 3 ms / 2,000 ms |
コード長 | 623 bytes |
コンパイル時間 | 1,542 ms |
コンパイル使用メモリ | 168,324 KB |
実行使用メモリ | 6,820 KB |
最終ジャッジ日時 | 2024-10-01 07:31:33 |
合計ジャッジ時間 | 2,568 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 23 |
ソースコード
#include<bits/stdc++.h> using namespace std; using ll = long long; int main(){ int a, b; cin >> a >> b; if(a == 1 || b == 1){ cout << 0 << "\n"; return 0; } int c = max(a, b); int d = min(a, b); int r = c % d; while(r != 0){ c = d; d = r; r = c % d; } if(d != 1){ cout << -1 << "\n"; return 0; } int ans = 0; vector<int> dp(100000, 0); dp[0] = 1; for (int i = 0; i <= a * b; i++){ if(dp[i] == 1){ dp[i + a] = 1; dp[i + b] = 1; } } for(int i=0; i<=a*b; i++){ if(dp[i] == 0){ ans++; } } cout << ans << "\n"; return 0; }