結果

問題 No.816 Beautiful tuples
ユーザー tonyu0tonyu0
提出日時 2019-11-02 00:59:02
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 592 bytes
コンパイル時間 882 ms
コンパイル使用メモリ 95,168 KB
実行使用メモリ 4,352 KB
最終ジャッジ日時 2023-10-13 01:04:40
合計ジャッジ時間 1,686 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 2 ms
4,352 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 WA -
testcase_04 AC 1 ms
4,352 KB
testcase_05 AC 2 ms
4,352 KB
testcase_06 AC 1 ms
4,348 KB
testcase_07 AC 1 ms
4,348 KB
testcase_08 AC 1 ms
4,348 KB
testcase_09 AC 2 ms
4,352 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 AC 2 ms
4,348 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) {
    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