結果

問題 No.816 Beautiful tuples
ユーザー tonyu0tonyu0
提出日時 2019-11-02 00:59:57
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 1,500 ms
コード長 626 bytes
コンパイル時間 1,094 ms
コンパイル使用メモリ 108,380 KB
実行使用メモリ 4,356 KB
最終ジャッジ日時 2023-10-13 01:04:44
合計ジャッジ時間 1,795 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 1 ms
4,352 KB
testcase_02 AC 1 ms
4,352 KB
testcase_03 AC 2 ms
4,352 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 2 ms
4,352 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 1 ms
4,352 KB
testcase_08 AC 2 ms
4,356 KB
testcase_09 AC 1 ms
4,348 KB
testcase_10 AC 2 ms
4,352 KB
testcase_11 AC 2 ms
4,352 KB
testcase_12 AC 2 ms
4,356 KB
testcase_13 AC 2 ms
4,352 KB
testcase_14 AC 1 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <iomanip>
#include <cmath>
#include <map>
using namespace std;
using ll = long long;

ll A, B;

int main() {
  cin >> A >> B;
  ll C = A + B;

  vector<int> div;
  for(int i = 1; i * i <= C; ++i) {
    if(C % i == 0) {
      div.push_back(i);
      if(C != i * i) div.push_back(C / i);
    }
  }
  sort(div.begin(), div.end());
  for(int d : div) {
    if(d == A || d == B) continue;
    ll a = A + d;
    ll b = B + d;
    if(a % B == 0 && b % A == 0) {
      cout << d << endl;
      return 0;
    }
  }
  cout << -1 << endl;
  return 0;
}
0