結果

問題 No.816 Beautiful tuples
ユーザー FF256grhyFF256grhy
提出日時 2019-04-19 21:25:11
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,704 bytes
コンパイル時間 1,749 ms
コンパイル使用メモリ 178,292 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-23 23:03:55
合計ジャッジ時間 2,468 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 WA -
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 2 ms
4,348 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 AC 2 ms
4,348 KB
testcase_13 AC 2 ms
4,348 KB
testcase_14 AC 2 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef long long   signed int LL;
typedef long long unsigned int LU;
#define incII(i, l, r) for(int i = (l)    ; i <= (r); ++i)
#define incID(i, l, r) for(int i = (l)    ; i <  (r); ++i)
#define decII(i, l, r) for(int i = (r)    ; i >= (l); --i)
#define decID(i, l, r) for(int i = (r) - 1; i >= (l); --i)
#define inc(i, n)  incID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define dec(i, n)  decID(i, 0, n)
#define dec1(i, n) decII(i, 1, n)
#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define  ALL(v)  v.begin(),  v.end()
#define RALL(v) v.rbegin(), v.rend()
template<typename T> bool setmin  (T & a, T b) { if(b <  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmax  (T & a, T b) { if(b >  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmineq(T & a, T b) { if(b <= a) { a = b; return true; } else { return false; } }
template<typename T> bool setmaxeq(T & a, T b) { if(b >= a) { a = b; return true; } else { return false; } }
LL mo(LL a, LL b) { assert(b > 0); a %= b; if(a < 0) { a += b; } return a; }
LL fl(LL a, LL b) { assert(b > 0); return (a > 0 ? a / b : (a - b + 1) / b); }
LL ce(LL a, LL b) { assert(b > 0); return (a < 0 ? a / b : (a + b - 1) / b); }
#define bit(b, i) (((b) >> (i)) & 1)
#define BC __builtin_popcountll
#define SC(T, v) static_cast<T>(v)
#define SI(v) SC(int, v.size())
#define SL(v) SC( LL, v.size())
#define RF(e, v) for(auto & e: v)
#define ei else if
#define UR assert(false)

// ---- ----

bool next_array(vector<int> & a, const vector<int> & b) {
	int d = a.size();
	inc(i, d + 1) {
		if(i == d) { return false; }
		a[i]++;
		if(a[i] == b[i]) { a[i] = 0; } else { break; }
	}
	return true;
}

vector<pair<LL, LL>> prime_factorization(LL x) {
	assert(x > 0);
	
	vector<pair<LL, LL>> f;
	LL i = 2;
	while(true) {
		if(x == 1) { break; }
		
		if(i * i > x) { i = x; }
		if(x % i == 0) {
			f.EB(i, 0);
			while(x % i == 0) { f.back().SE++; x /= i; }
		}
		i++;
	}
	
	return f;
}

vector<LL> divisor(LL x) {
	assert(x > 0);
	
	auto f = prime_factorization(x);
	LL fs = f.size();
	vector<int> a(fs), b(fs);
	inc(i, fs) { b[i] = f[i].SE + 1; }
	
	vector<LL> g;
	do {
		LL v = 1;
		inc(i, fs) {
		inc(j, a[i]) {
			v *= f[i].FI;
		}
		}
		g.PB(v);
	} while(next_array(a, b));
	sort(ALL(g));
	
	return g;
}

LL a, b;

int main() {
	cin >> a >> b;
	
	auto x = divisor(a + b);
	
	LL ans = -1;
	RF(e, x) {
		if((a + e) % b == 0 && (b + e) % a == 0) { ans = e; break; }
	}
	
	cout << ans << endl;
	
	return 0;
}
0