結果

問題 No.982 Add
ユーザー 👑 zeronosu77108zeronosu77108
提出日時 2020-02-11 14:31:27
言語 C++17(clang)
(14.0.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 1,423 bytes
コンパイル時間 1,019 ms
コンパイル使用メモリ 104,912 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-20 13:52:54
合計ジャッジ時間 1,844 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 2 ms
4,376 KB
testcase_14 AC 1 ms
4,380 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 2 ms
4,376 KB
testcase_17 AC 1 ms
4,376 KB
testcase_18 AC 2 ms
4,380 KB
testcase_19 AC 2 ms
4,376 KB
testcase_20 AC 1 ms
4,376 KB
testcase_21 AC 1 ms
4,376 KB
testcase_22 AC 1 ms
4,376 KB
testcase_23 AC 2 ms
4,376 KB
testcase_24 AC 2 ms
4,376 KB
testcase_25 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <iomanip>
#include <vector>
#include <utility>
#include <map>
#include <algorithm>
#include <queue>
#include <cmath>
#include <numeric>
#include <set>

using namespace std;
struct aaa{aaa(){cin.tie(nullptr); ios::sync_with_stdio(false); cout<<fixed<<setprecision(20);};}aaa;
template <class T>ostream &operator<<(ostream &o,const vector<T>&v){o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}
#define debug(v) {cerr<<"\033[1;36m[debug]\033[m "<<#v<<" : "<<v<<endl;}

using int64 = long long;

vector<bool> diviser(int n) {
    vector<bool> d(n+1);
    for (int i=2; i*i<=n; i++) {
        if (n % i == 0) {
            d[i] = true;
            while(n % i == 0) n/=i;
        }
    }
    if (n != 1) d[n] = true;
    return d;
}

int main() {
    int a,b;
    cin >> a >> b;
    vector<bool> diva = diviser(a);
    vector<bool> divb = diviser(b);

    if (a == 1 || b == 1) {
        cout << 0 << endl;
        return 0;
    }

//    debug(diva);
//    debug(divb);
    for (int i=2; i<=min(a,b); i++)
        if (diva[i] && divb[i]) {
            cout << -1 << endl;
            return 0;
        }

    vector<bool> dp(10000,false);
    dp[0] = true;
    for (int i=a; i<10000; i++) dp[i] = dp[i] || dp[i-a];
    for (int i=b; i<10000; i++) dp[i] = dp[i] || dp[i-b];

    int ans = 0;
    for (int i=0; i<10000; i++) if (!dp[i]) ans++;
    cout << ans << endl;
}
0