用户输出
4
系统信息
Exited with return code 0
编号 | 题目 | 状态 | 分数 | 总时间 | 内存 | 代码 / 答案文件 | 提交者 | 提交时间 |
---|---|---|---|---|---|---|---|---|
#21343 | #1070. 脸盲的zzy和jwp | Accepted | 100 | 24 ms | 356 K | C++ 17 / 1.0 K | 自动化82-郭筠陶 | 2020-02-05 15:51:56 |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll x1, v1, x2, v2, len;
ll exgcd(ll a, ll b, ll& x, ll& y);
int main() {
cin >> x1 >> v1 >> x2 >> v2 >> len;
if (v1 == v2) {
if (x1 != x2)
cout << -1;
else
cout << 0;
return 0;
}
ll v = (v1 - v2 + len) % len, x = (x2 - x1 + len) % len, t0, k;
int gcd = exgcd(v, len, t0, k);
if (x % gcd != 0) {
cout << -1;
} else {
ll nx = x / gcd, t = t0 * nx, nlen = len / gcd;
t = (t % nlen + nlen) % nlen;
/*cout << v << "\t" << x << "\t" << t << "\t" << k << "\t" << gcd << "\t" << nlen << "\t" << t0 << t
* << endl;*/
cout << t;
}
}
ll exgcd(ll a, ll b, ll& x, ll& y) { //扩展欧几里得算法
if (b == 0) {
x = 1;
y = 0;
return a; //到达递归边界开始向上一层返回
}
int r = exgcd(b, a % b, x, y);
int temp = y; //把x y变成上一层的
y = x - (a / b) * y;
x = temp;
return r; //得到a b的最大公因数
}
用户输出
175111586
系统信息
Exited with return code 0
用户输出
91595156
系统信息
Exited with return code 0
用户输出
6586798
系统信息
Exited with return code 0
用户输出
83740797
系统信息
Exited with return code 0
用户输出
116043662
系统信息
Exited with return code 0
用户输出
42763932
系统信息
Exited with return code 0
用户输出
445951169
系统信息
Exited with return code 0
用户输出
169591840
系统信息
Exited with return code 0
用户输出
-1
系统信息
Exited with return code 0
用户输出
-1
系统信息
Exited with return code 0