結果
問題 | No.982 Add |
ユーザー |
|
提出日時 | 2020-02-11 13:34:15 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 2 ms / 2,000 ms |
コード長 | 1,706 bytes |
コンパイル時間 | 1,508 ms |
コンパイル使用メモリ | 168,116 KB |
実行使用メモリ | 6,820 KB |
最終ジャッジ日時 | 2024-10-01 07:20:56 |
合計ジャッジ時間 | 2,081 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 23 |
ソースコード
#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#endifll 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;}