結果

問題 No.816 Beautiful tuples
ユーザー YamaKasa
提出日時 2019-06-26 20:30:47
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 3 ms / 1,500 ms
コード長 543 bytes
コンパイル時間 2,222 ms
コンパイル使用メモリ 167,300 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-06-26 01:23:13
合計ジャッジ時間 2,134 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 15
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll A, B;
  cin >> A >> B;
  ll m = sqrt(A + B);
  ll t = A + B;
  for (ll k = 1; k <= m; k++) {
    if (t % k == 0) {
      ll C1 = k;
      ll C2 = (A + B) / k;
      if ((B + C1) % A == 0 && (A + C1) % B == 0) {
        cout << C1 << "\n";
        return 0;
      }
      if ((B + C2) % A == 0 && (A + C2) % B == 0) {
        cout << C2 << "\n";
        return 0;
      }
    }
  }
  cout << "-1\n";
  return 0;
}
0