結果

問題 No.816 Beautiful tuples
ユーザー tomatoma
提出日時 2019-04-19 21:32:33
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 1,500 ms
コード長 893 bytes
コンパイル時間 1,850 ms
コンパイル使用メモリ 167,324 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-23 23:40:25
合計ジャッジ時間 2,165 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include"bits/stdc++.h"

using namespace std;
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

#define FOR(k,m,n) for(ll (k)=(m);(k)<(n);(k)++)
#define REP(i,n) FOR((i),0,(n))
#define WAITING(str) int str;std::cin>>str;
#define DEBUGING(str) cout<< #str << " " str<<endl

constexpr int INF = (1 << 30);
constexpr ll INFL = (1ll << 60);
constexpr ll MOD = 1000000007;// 10^9+7



int main()
{
	ll A, B, C;
	cin >> A >> B;
	C = A + B;
	ll best = INFL;
	FOR(i, 1, sqrt(C) + 10) {
		if (C%i == 0) {
			if ((A + i) % B != 0)goto next;
			if ((B + i) % A != 0)goto next;
			if (i == A || i == B)goto next;
			best = min(best, i);
		next:;
			ll j = C / i;
			if ((A + j) % B != 0)continue;
			if ((B + j) % A != 0)continue;
			if (j == A || j == B)continue;
			best = min(best, j);
		}
	}
	cout << (best == INFL ? -1 : best) << endl;
	return 0;
}
0