結果

問題 No.816 Beautiful tuples
ユーザー yuruhiyayuruhiya
提出日時 2019-04-20 14:51:37
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 3 ms / 1,500 ms
コード長 1,238 bytes
コンパイル時間 1,654 ms
コンパイル使用メモリ 170,672 KB
実行使用メモリ 6,676 KB
最終ジャッジ日時 2024-04-08 16:21:55
合計ジャッジ時間 2,380 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#define _CRT_SECURE_NO_WARNINGS
#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for(int i=0; i<(n); ++i)
#define FOR(i, m, n) for(int i=(m); i<(n); ++i)
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define mp make_pair
#define pb push_back
#define Cout(x) cout << (x) << endl
#define dump(x) cerr << #x << " = " << (x) << endl;
typedef long long LL;
typedef vector<int> VI;
typedef vector<long long> VL;
typedef vector<string> VS;
typedef vector<vector<int>> VVI;
typedef pair<int, int> PII;
const int inf = (int)1e9;
const long long mod = (long long)1e9 + 7;
const double pi = acos(-1.0);

//約数列挙
vector<long long> DivAll(long long n) {
	vector<long long> ret;
	long long i = 1;
	for (; i * i < n; ++i)
		if (n % i == 0)ret.push_back(i);
	bool flag = i * i == n;
	if (flag)ret.push_back(i);
	for (i = (int)ret.size() - 1 - flag; i >= 0; --i)
		ret.push_back(n / ret[i]);
	return ret;
}

bool re(int a, int b, int c) {
	return (a != b && b != c && a != c) && ((a + b) % c == 0) && ((a + c) % b == 0) && ((b + c) % a == 0);
}

int main() {
	LL a, b; cin >> a >> b;
	VL div = DivAll(a + b);

	int ans = -1;
	for (auto n : div) {
		if (re(a, b, n)) {
			ans = n;
			break;
		}
	}
	Cout(ans);
}
0