結果

問題 No.186 中華風 (Easy)
ユーザー tarakojo1019tarakojo1019
提出日時 2020-12-20 13:18:29
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 3,116 bytes
コンパイル時間 7,090 ms
コンパイル使用メモリ 361,260 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-21 10:38:47
合計ジャッジ時間 8,274 ms
ジャッジサーバーID
(参考情報)
judge12 / judge9
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include<iostream>
#include<math.h>
#include<algorithm>
#include<stdint.h>
#include<vector>
#include<deque>
#include<stack>
#include<functional>
#include<string>
#include<cstring>
#include<array>
#include<fstream>
#include<iomanip>
#include<list>
#include<set>
#include<map>
#include<unordered_map>
#include<unordered_set>
#include<bitset>
#include<queue>

using namespace std;

using ll = long long;
using ull = unsigned long long;

#define REP(i,a,b) for(ll i = a; i < b; ++i)
#define PRI(s) std::cout << s << endl
#define PRIF(v, n) printf("%."#n"f\n", (double)v)

template<typename A, typename B>void mins(A& a, const B& b) { a = min(a, (A)b); };
template<typename A, typename B>void maxs(A & a, const B & b) { a = max(a, (A)b); };

template<typename T> void cumulative_sum(const vector<T>& src, vector<T>& ans) {
	ans.resize(src.size() + 1);
	ans[0] = 0;
	REP(i, 0, src.size()) ans[i + 1] = ans[i] + src[i];
}


#include<boost/multiprecision/cpp_int.hpp>
using namespace boost::multiprecision;


//素因数分解
std::vector<std::pair<long long, int>> factorize(long long n) {
	std::vector<std::pair<long long, int>> res;
	for (long long i = 2; i * i <= n; ++i) {
		if (n % i != 0) continue;
		res.emplace_back(i, 0);
		while (n % i == 0) {
			n /= i;
			res.back().second++;
		}
	}
	if (n != 1) res.emplace_back(n, 1);
	return res;
}


ll check(vector<pair<ll, int>>& v, ll a, ll b, ll ind) {
	if (ind == v.size()) {
		if (abs(a - b) == 1) return min(a, b);
		else return 1e18;
	}
	ll tmp = 1;
	for (int i = 0; i < v[ind].second; ++i) tmp *= v[ind].first;
	return  min(check(v, a * tmp, b, ind + 1), check(v, a, b * tmp, ind + 1));
}



//最大公約数
template<typename T>T gcd(T a, T b) {
	if (b == 0)return a;
	return gcd(b, a % b);
}
//最小公倍数
template<typename T>T lcm(T a, T b)
{
	return a * b / gcd(a, b);
}

//拡張ユークリッドの互除法。戻り値は最大公約数、x,yはax+by=gcd(a,b)を満たす組の一つ
template<typename T> T gcdext(T a, T b, T& x, T& y) {
	if (b == 0) {
		x = 1;
		y = 0;
		return a;
	}
	T g = gcdext<T>(b, a % b, y, x);
	y -= a / b * x;
	return g;
}

//中国剰余定理 x % mod1 == v1 % mod1, x % mod2 == v2 % mod2 と同値な合同式 x % lcm(mod1, mod2) == r % lcm の(r, lcm)を求める。
//解が存在する条件は、v1 % gcd(mod1, mod2) == v2 % gcd(mod1, mod2)
template<typename T> pair<T, T> CRT(T v1, T mod1, T v2, T mod2) {
	if (mod1 <= 0 || mod2 <= 0) return { 0,0 };
	T p, q;
	T g = gcdext(mod1, mod2, p, q);
	if ((v2 - v1) % g != 0)return { 0, 0 };
	T s = (v2 - v1) / g;
	T mod = lcm(mod1, mod2);
	T r = v1 + s * mod1 % mod * p % mod;
	return { (r % mod + mod) % mod, mod };
}
template<typename T> pair<T, T> CRT(vector<pair<T, T>>& v) {
	pair<T, T> ans = { 0,1 };
	for (auto p : v) ans = CRT(ans.first, ans.second, p.first, p.second);
	return ans;
}



int main() {
	pair<cpp_int,cpp_int> ans = { 0,1 };
	for (int i = 0; i < 3; ++i) {
		cpp_int x, y; cin >> x >> y;
		ans = CRT(ans.first, ans.second, x, y);
	}
	if (ans.second == 0) PRI(-1);
	else {
		if (ans.first == 0) ans.first += ans.second;
		PRI(ans.first);
	}
	return 0;
}
0