結果
| 問題 |
No.186 中華風 (Easy)
|
| コンテスト | |
| ユーザー |
f1b_maxbl00d
|
| 提出日時 | 2022-06-17 17:38:50 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 2,000 ms |
| コード長 | 3,816 bytes |
| コンパイル時間 | 1,136 ms |
| コンパイル使用メモリ | 124,968 KB |
| 最終ジャッジ日時 | 2025-01-29 21:20:51 |
|
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 23 |
ソースコード
//#pragma warning(disable:4996)
//#include <Windows.h>
#include <iostream>
#include <vector>
#include <limits.h>
#include <algorithm>
#include <string>
#include <math.h>
#include <limits.h>
#include <queue>
#include <map>
#include <set>
#include <iomanip>
#include <bitset>
#include <cassert>
#include <random>
#include <functional>
#include <stack>
#include <iomanip>
#include <cassert>
//#include <boost/multiprecision/cpp_int.hpp>
#include <complex>
#include <cstdio>
#include <list>
#include <bitset>
//#include <stdio.h>
//< in.txt > out.txt
using namespace std;
//std::ios::sync_with_stdio(false);
//std::cin.tie(0);
const long long MOD = 1e9 + 7;
const long long INF = 1e18;
typedef long long LL;
typedef long double LD;
typedef unsigned long long ULL;
//typedef boost::multiprecision::cpp_int bigint;
typedef pair<LL, LL> PLL;
typedef pair<int, int> PI;
typedef pair<LD, LL> pdl;
typedef pair<LD, LD> pdd;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;
typedef vector<int> VI;
typedef vector<vector<int>> VVI;
typedef unsigned long long ULL;
template<class T>
using pqueue = priority_queue<T, vector<T>, function<bool(T, T)>>;
template<class T>
inline void chmin(T& a, T b) {
a = min(a, b);
}
template<class T>
inline void chmax(T& a, T b) {
a = max(a, b);
}
//y/xのfloorを求める
LL floor_(LL y, LL x) {
if (x < 0) {
x *= -1;
y *= -1;
}
if (y >= 0) {
return y / x;
}
else {
if ((-y) % x == 0) {
return y / x;
}
else {
return -((-y) / x) - 1;
}
}
}
//a mod mを求める
inline LL mod(LL a, LL m) {
LL res = a % m;
if (res < 0) {
res += m;
}
return res;
}
void input();
void solve();
void daminput();
void naive();
void outputinput();
int main() {
std::cin.tie(0);
std::ios::sync_with_stdio(false);
cout << fixed << setprecision(12);
input();
//daminput();
solve();
//naive();
//outputinput();
return 0;
}
//////////////////////////////////////////////////
//////////////////////////////////////////////////
//最大公約数
//O(log max(a,b))
template<class T>
T GCD(T a, T b) {
if (b == 0)return a;
return GCD(b, (T)(a % b));
}
//最大公約数(複数)
//O(nlog max(a_i))?
template<class T>
T GCD(vector<T> v) {
for (int n = 1; n < v.size(); n++) {
v[n] = GCD(v[n], v[n - 1]);
}
return v[v.size() - 1];
}
//最小公倍数
template<class T>
T LCM(T a, T b) {
return a * b / GCD(a, b);
}
//最小公倍数(複数)
template<class T>
T LCM(vector<T> v) {
for (int n = 1; n < v.size(); n++) {
v[n] = LCM(v[n], v[n - 1]);
}
return v[v.size() - 1];
}
//ax+by=gcd(a,b)の解
LL extgcd(LL a, LL b, LL& x, LL& y) {
LL d = a;
if (b != 0) {
d = extgcd(b, a % b, y, x);
y -= (a / b) * x;
}
else {
x = 1; y = 0;
}
return d;
}
//ax=gcd(a,m) mod mなるxを返す
LL ModInv(LL a, LL m) {
LL x, y;
extgcd(a, m, x, y);
return x;
}
//x = b1 mod m1
//x = b2 mod m2
//なる連立合同式を解く mod lcm(m1,m2)において解が存在するならば(x,lcm(m1,m2))を、存在しないならば(0,-1)を返す
PLL SimCongruence(LL b1, LL m1, LL b2, LL m2) {
LL p, q;
LL d = extgcd(m1, m2, p, q);
if ((b1 - b2) % d != 0) {
return PLL(0,-1);
}
else {
LL m = m1 / d * m2;
LL tmp = (b2 - b1) / d * p % (m2 / d);
LL r = mod(b1 + m1 * tmp, m);
return PLL(r, m);
}
}
LL X1, X2, X3;
LL Y1, Y2, Y3;
void input() {
cin >> X1 >> Y1;
cin >> X2 >> Y2;
cin >> X3 >> Y3;
}
void daminput() {
}
void solve() {
LL X12, Y12;
tie(X12, Y12) = SimCongruence(X1, Y1, X2, Y2);
if (Y12 == -1) {
cout << -1 << "\n";
return;
}
X12 = mod(X12, Y12);
LL X123, Y123;
tie(X123, Y123) = SimCongruence(X12, Y12, X3, Y3);
if (Y123 == -1) {
cout << -1 << "\n";
return;
}
else {
if (X123 == 0) {
cout << Y123 << "\n";
}
else {
cout << mod(X123, Y123) << "\n";
}
}
}
void naive() {
}
void outputinput() {
}
f1b_maxbl00d