結果

問題 No.816 Beautiful tuples
ユーザー kakulin_realkakulin_real
提出日時 2019-04-22 09:53:03
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 3 ms / 1,500 ms
コード長 680 bytes
コンパイル時間 1,704 ms
コンパイル使用メモリ 162,564 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-17 23:37:33
合計ジャッジ時間 2,262 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef vector<ll> vl;
typedef long double ld;
typedef vector<ld> vd;
typedef bool bl;
typedef vector<bl> vb;
typedef unordered_map<ll,unordered_map<ll,ll>> graph;

const ll e5 = 1 << 20;
const ll mod = 998244353;
const ll e3 = 1 << 13;
const ll INF = 1ll << 60;

ll a,b;
ll c;
ll ans = INF;

int main(){
  cin >> a >> b;
  for(c = 1;c*c <= a+b;c++){
    if((a+b)%c == 0){
      if(c != a && c != b && (a+c)%b == 0 && (b+c)%a == 0) ans = min(ans,c);
      ll c_ = (a+b)/c;
      if(c_ != a && c_ != b && (a+c_)%b == 0 && (b+c_)%a == 0) ans = min(ans,c_);
    }
  }
  cout << (ans == INF ? -1 : ans) << endl;
}
0