結果

問題 No.982 Add
ユーザー EnderedEndered
提出日時 2020-02-11 13:34:15
言語 C++14
(gcc 11.2.0 + boost 1.78.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 1,706 bytes
コンパイル時間 1,353 ms
使用メモリ 3,548 KB
最終ジャッジ日時 2022-11-24 17:19:20
合計ジャッジ時間 2,688 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
使用メモリ
testcase_00 AC 2 ms
3,488 KB
testcase_01 AC 1 ms
3,548 KB
testcase_02 AC 2 ms
3,492 KB
testcase_03 AC 1 ms
3,548 KB
testcase_04 AC 2 ms
3,544 KB
testcase_05 AC 1 ms
3,520 KB
testcase_06 AC 2 ms
3,484 KB
testcase_07 AC 2 ms
3,436 KB
testcase_08 AC 1 ms
3,364 KB
testcase_09 AC 1 ms
3,436 KB
testcase_10 AC 1 ms
3,476 KB
testcase_11 AC 1 ms
3,436 KB
testcase_12 AC 1 ms
3,432 KB
testcase_13 AC 1 ms
3,444 KB
testcase_14 AC 2 ms
3,528 KB
testcase_15 AC 1 ms
3,372 KB
testcase_16 AC 1 ms
3,404 KB
testcase_17 AC 2 ms
3,532 KB
testcase_18 AC 1 ms
3,368 KB
testcase_19 AC 1 ms
3,444 KB
testcase_20 AC 1 ms
3,492 KB
testcase_21 AC 2 ms
3,476 KB
testcase_22 AC 1 ms
3,364 KB
testcase_23 AC 2 ms
3,444 KB
testcase_24 AC 1 ms
3,516 KB
testcase_25 AC 2 ms
3,436 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
#define rep(i, n) for(int i=0;i<(n);++i)
#define per(i, n) for(int i=(n)-1;i>=0;--i)
#define repa(i, n) for(int i=1;i<(n);++i)
#define foreach(i, n) for(auto &i:(n))
#define pii pair<int, int>
#define pll pair<long long, long long>
#define all(x) (x).begin(), (x).end()
#define bit(x) (1ll << (x))
using ll = long long;
//const ll MOD = (ll)1e9+7;
const ll MOD = 998244353;
const int INF = (ll)1e9+7;
const ll INFLL = (ll)1e18;
using namespace std;
template<class t>
using vvector = vector<vector<t>>;
template<class t>
using vvvector = vector<vector<vector<t>>>;
template<class t>
using priority_queuer = priority_queue<t, vector<t>, greater<t>>;
template<class t, class u> bool chmax(t &a, u b){if(a<b){a=b;return true;}return false;}
template<class t, class u> bool chmin(t &a, u b){if(a>b){a=b;return true;}return false;}
#ifdef DEBUG
#define OUTPUT(x) (output(x), output("\n"))
#else
#define OUTPUT(x) (void)0
#endif

ll modpow(ll x, ll b){
    ll res = 1;
    while(b){
        if(b&1)res = res * x % MOD;
        x = x * x % MOD;
        b>>=1;
    }
    return res;
}

ll modinv(ll x){
    return modpow(x, MOD-2);
}

bool was_output = false;
template<class t>
void output(t a){
    if(was_output)cout << " ";
    cout << a;
    was_output = true;
}
void outendl(){
    was_output = false;
    cout << endl;
}


ll gcd(ll a, ll b){
    while(b){
        a %= b;
        swap(a, b);
    }
    return a;
}

ll lcm(ll a, ll b){
    return a / gcd(a, b) * b;
}

int main(){
    ll a;
    ll b;
    cin >> a >> b;
    ll lc = lcm(a, b);
    if(gcd(a, b)!=1){
        cout << -1 << endl;
        return 0;
    }
    cout << (lc - lc / a - lc / b + 1) / 2 << endl;
    return 0;
}
0