結果

問題 No.982 Add
ユーザー ferin
提出日時 2020-02-11 14:22:05
言語 C++17(gcc12)
(gcc 12.3.0 + boost 1.87.0)
結果
AC  
実行時間 1,961 ms / 2,000 ms
コード長 1,051 bytes
コンパイル時間 7,303 ms
コンパイル使用メモリ 261,496 KB
最終ジャッジ日時 2025-01-08 23:37:34
ジャッジサーバーID
(参考情報)
judge2 / judge3
純コード判定しない問題か言語
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 23
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using PII = pair<ll, ll>;
#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
template<typename T> void chmin(T &a, const T &b) { a = min(a, b); }
template<typename T> void chmax(T &a, const T &b) { a = max(a, b); }
struct FastIO {FastIO() { cin.tie(0); ios::sync_with_stdio(0); }}fastiofastio;
#ifdef DEBUG_ 
#include "../program_contest_library/memo/dump.hpp"
#else
#define dump(...)
#endif
const ll INF = 1LL<<60;

int main(void) {
    ll a, b;
    cin >> a >> b;

    if(gcd(a, b) != 1) {
        cout << -1 << endl;
        return 0;
    }

    vector<ll> v;
    REP(i, 5000) REP(j, 5000) if(a*i+b*j>0) v.push_back(a*i+b*j);
    sort(ALL(v));
    v.erase(unique(ALL(v)), v.end());
    // {
    //     vector<ll> d;
    //     REP(i, 400) d.push_back(v[i]);
    //     dump(d);
    // }

    ll sz = min((ll)v.size(), 20000LL);
    dump(v.back(), v.size());

    cout << v[sz-1] - sz << endl; 

    return 0;
}
0