QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#21573 | #2845. 密码学第三次小作业 | Skyowo# | AC ✓ | 27ms | 3700kb | C++14 | 1.3kb | 2022-03-07 15:14:47 | 2022-05-08 03:39:18 |
Judging History
answer
// Skyqwq
#include <bits/stdc++.h>
#define pb push_back
#define fi first
#define se second
#define mp make_pair
using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
template <typename T> bool chkMax(T &x, T y) { return (y > x) ? x = y, 1 : 0; }
template <typename T> bool chkMin(T &x, T y) { return (y < x) ? x = y, 1 : 0; }
#define I __int128
template <typename T> void inline read(T &x) {
int f = 1; x = 0; char s = getchar();
while (s < '0' || s > '9') { if (s == '-') f = -1; s = getchar(); }
while (s <= '9' && s >= '0') x = x * 10 + (s ^ 48), s = getchar();
x *= f;
}
I c1, c2, e1, e2, P;
I exgcd(I a, I b, I &x, I &y) {
if (!b) {
x = 1, y = 0;
return a;
}
LL d = exgcd(b, a % b, y, x);
y -= a / b * x;
return d;
}
I inv(I a) {
I A, B;
exgcd(a, P, A, B);
return (A % P + P) % P;
}
I power(I a, I b) {
if (b < 0) return power(inv(a), -b);
I ret = 1;
while (b) {
if (b & 1) ret = ret * a % P;
a = a * a % P;
b >>= 1;
}
return ret;
}
int main() {
int T; read(T);
while (T--) {
read(c1), read(c2), read(e1), read(e2); read(P);
I A, B;
I o = exgcd(e1, e2, A, B);
I ans = power(c1, A) * power(c2, B) % P;
printf("%lld\n", (LL)ans);
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 5ms
memory: 3608kb
input:
10000 194765009 590879477 22481 11801 596329817 437621144 509036484 18587 3203 820537651 645177263 749030649 5821 13931 905781727 246944928 634474710 467 23371 726675529 605059247 536773554 21499 11519 733241959 53572985 261038149 23209 1303 679323269 314446191 738402036 12973 28961 825774259 359483...
output:
3745484 95327130 296809360 260917393 5910400 215017122 209461189 9944422 328546137 422624753 134605625 460020274 532874246 515467840 414967122 584661331 575708794 455212601 34579391 300543756 297635435 829111593 257490797 377499646 339663690 530810590 430294196 279963294 314834816 346080261 43793086...
result:
ok (10000 test cases)
Test #2:
score: 0
Accepted
time: 27ms
memory: 3700kb
input:
10000 421334545191079239 447565396010357899 607319 686761 555388527903369997 482840423399033737 434258320005377506 168083 52711 699821164707511453 342876142292626109 418004883829192067 466201 672913 706900388919931487 239546138630487720 2083287231715587034 879247 532417 2580420336112804147 218169150...
output:
455273291313157504 46398738587396768 72660497104269680 988613982675111040 587199639602402688 481927093525894400 142105005862797856 178522718341774624 145106382430967040 197414524611321696 1659534362403244032 3922428012540531 1129237605899348736 416304549016197248 234913278456251680 15138153767239190...
result:
ok (10000 test cases)