用户输出
4
系统信息
Exited with return code 0
编号 | 题目 | 状态 | 分数 | 总时间 | 内存 | 代码 / 答案文件 | 提交者 | 提交时间 |
---|---|---|---|---|---|---|---|---|
#20966 | #1070. 脸盲的zzy和jwp | Accepted | 100 | 22 ms | 356 K | C++ 17 / 816 B | Diorvh | 2019-09-05 13:29:28 |
#include <bits/stdc++.h>
using namespace std;
#define LL long long
#define ll long long
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll exgcd(ll a, ll b, ll &x, ll &y) {
if (!b) {
x = 1, y = 0;
return a;
}
ll d = exgcd(b, a % b, y, x);
y = y - a / b * x;
return d;
}
bool lnmodpositive(LL a, LL &x, LL c, LL nmod) //求线性同余方程
{
if (a < 0)
a *= -1, c *= -1;
LL g = gcd(a, nmod), ca;
c = (c % nmod + nmod) % nmod;
if (a == 0 || c % g != 0)
return false;
exgcd(a, nmod, x, ca);
LL k = nmod / g;
x = (x % k + k) % k;
x = x * c / g % nmod;
return true;
}
int main() {
ll x, a, y, b, l;
scanf("%lld%lld%lld%lld%lld", &x, &a, &y, &b, &l);
ll t;
if (lnmodpositive(a - b, t, y - x, l))
printf("%lld\n", t);
else
printf("-1\n");
return 0;
}
用户输出
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