結果

問題 No.816 Beautiful tuples
ユーザー developmasodevelopmaso
提出日時 2019-04-19 22:08:42
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,576 bytes
コンパイル時間 2,324 ms
コンパイル使用メモリ 167,492 KB
実行使用メモリ 8,744 KB
最終ジャッジ日時 2023-10-24 03:15:48
合計ジャッジ時間 13,191 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
8,744 KB
testcase_01 AC 2 ms
4,372 KB
testcase_02 AC 71 ms
4,372 KB
testcase_03 AC 218 ms
4,372 KB
testcase_04 AC 77 ms
4,372 KB
testcase_05 TLE -
testcase_06 AC 158 ms
4,372 KB
testcase_07 AC 241 ms
4,372 KB
testcase_08 AC 138 ms
4,372 KB
testcase_09 AC 171 ms
4,372 KB
testcase_10 TLE -
testcase_11 TLE -
testcase_12 TLE -
testcase_13 -- -
testcase_14 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#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;

}
0