結果
問題 | No.816 Beautiful tuples |
ユーザー |
![]() |
提出日時 | 2019-04-19 22:08:42 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
TLE
|
実行時間 | - |
コード長 | 1,576 bytes |
コンパイル時間 | 1,509 ms |
コンパイル使用メモリ | 166,804 KB |
実行使用メモリ | 13,760 KB |
最終ジャッジ日時 | 2024-09-22 20:15:51 |
合計ジャッジ時間 | 12,253 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 9 TLE * 4 -- * 2 |
ソースコード
#include <bits/stdc++.h> #define rep(i,a,b) for(int i=(int)(a);i<(int)(b);++i) #define rrep(i,a,b) for(int i=(int)(a);i>=(int)(b);--i) #define fore(i,a) for(auto &i:a) #define all(a) (a).begin(),(a).end() using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); } using ll = long long; constexpr int inf = INT_MAX / 2; constexpr ll infl = 1LL << 60; template<class T>void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; } template<class T>void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; } template<class T>void POSS(T condition){ if(condition) cout << "POSSIBLE" << endl; else cout << "IMPOSSIBLE" << endl; } template<class T>void Poss(T condition){ if(condition) cout << "Possible" << endl; else cout << "Impossible" << endl; } template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; } template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; } template<class T>T gcd(T a, T b){ if(a && b){ return gcd(min(a, b), max(a, b) % min(a, b)); }else{ return a; }} template<class T>T lcm(T a, T b){ return a / gcd(a, b) * b; } int A, B; int AB; bool IsOk(int c) { if (AB % c != 0) return false; if (A == c || B == c) return false; if ((A + c) % B != 0 || (B + c) % A != 0) return false; return true; } void _main() { cin >> A >> B; AB = A + B; int ans = -1; rep(i, 1, AB/2+1) { if (IsOk(i)) { ans = i; break; } } if (IsOk(AB)) ans = AB; cout << ans << endl; }