ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#215179 | #2686. Oversleeping | KXG | 30 | 2165ms | 512kb | C++11 | 1.1kb | 2024-11-26 22:32:51 | 2024-11-26 23:07:31 |
answer
#include <cstdio>
#include <algorithm>
using namespace std;
long long exgcd(long long a, long long b, long long & x, long long & y) {
if (b == 0) {
x = 1;
y = 0;
return a;
}
long long d = exgcd(b, a % b, x, y);
long long t = x;
x = y;
y = t - a / b * y;
return d;
}
long long query(long long a1, long long m1, long long a2, long long m2) {
long long x, y;
long long d = exgcd(a1, a2, x, y);
if ((m2 - m1) % d != 0) {
return 2e18;
}
// printf("%lld %lld %lld %lld : %lld %lld %lld\n", a1, m1, a2, m2, d, x, y);
long long mod = a1 * a2 / d;
return (((m2 - m1) / d * x % mod * a1 + m1) % mod + mod) % mod;
}
int t;
long long x, y, p, q;
int main() {
scanf("%d", &t);
while (t--) {
scanf("%lld%lld%lld%lld", &x, &y, &p, &q);
long long ans = 2e18;
for (long long i = x; i < x + y; i++) {
for (long long j = p; j < p + q; j++) {
ans = min(ans, query(2 * (x + y), i, (p + q), j));
}
}
if (ans == 2e18) ans = -1;
printf("%lld\n", ans);
}
return 0;
}
详细
小提示:点击横条可展开更详细的信息
Test #1:
score: 5
Accepted
time: 75ms
memory: 512kb
input:
10 42 337 468 315 179 261 297 332 336 189 230 33 240 398 38 204 465 158 454 462 112 184 90 263 320 4...
output:
1558 297 493 240 465 112 475 187 386 268
result:
ok 10 lines
Test #2:
score: 5
Accepted
time: 93ms
memory: 512kb
input:
10 96 471 276 491 226 87 207 365 451 201 191 173 46 375 100 8 39 179 214 269 135 260 91 431 253 288 ...
output:
276 226 555 100 214 135 458 374 378 99
result:
ok 10 lines
Test #3:
score: 5
Accepted
time: 79ms
memory: 512kb
input:
10 337 285 340 338 484 25 321 156 246 482 122 234 229 441 426 72 6 93 155 338 21 317 406 335 160 298...
output:
340 5574 246 426 204 697 372 469 437 492
result:
ok 10 lines
Test #4:
score: 5
Accepted
time: 64ms
memory: 512kb
input:
10 196 433 313 366 262 415 94 30 353 22 242 460 283 172 13 276 56 247 344 4 297 363 415 479 473 26 6...
output:
313 342 353 283 692 415 473 169 131 176
result:
ok 10 lines
Test #5:
score: 5
Accepted
time: 70ms
memory: 508kb
input:
10 437 267 140 198 383 155 226 424 273 308 151 317 15 231 435 285 404 294 253 64 109 199 388 147 425...
output:
478 383 273 507 570 923 427 467 328 123
result:
ok 10 lines
Test #6:
score: 5
Accepted
time: 41ms
memory: 512kb
input:
10 21 426 135 234 111 51 109 11 185 42 230 22 472 346 269 285 77 128 499 461 173 79 230 382 102 127 ...
output:
135 111 2001 472 499 230 207 297 268 141
result:
ok 10 lines
Test #7:
score: 0
Wrong Answer
time: 274ms
memory: 508kb
input:
10 790950658 153 395731486 328 228237805 89 805489534 371 733742769 407 150980036 116 210282811 256 ...
output:
616229844248532 604372927024593 303125267619252 1323102683248553 969332165912729 242609398794434 178...
result:
wrong answer 1st lines differ - expected: '493783472749894', found: '616229844248532'
Test #8:
score: 0
Wrong Answer
time: 226ms
memory: 508kb
input:
10 935151576 163 823994136 316 552819682 244 661178089 95 751586616 375 326537181 182 9424664 344 31...
output:
298190458199344 1084169841478881 751661443534920 8013759259638 676418896766543 251114165852027 13344...
result:
wrong answer 1st lines differ - expected: '3487138752902582', found: '298190458199344'
Test #9:
score: 0
Wrong Answer
time: 215ms
memory: 508kb
input:
10 480628854 293 138727635 133 188840646 190 569211831 53 442713615 341 668626439 341 527553711 268 ...
output:
1188085210142 590005983270571 924355157032259 65724850124158 1705965917913814 267162523565048 139168...
result:
wrong answer 1st lines differ - expected: '237399557723152', found: '1188085210142'
Test #10:
score: 0
Wrong Answer
time: 172ms
memory: 512kb
input:
10 128375946 395 45119743 26 591869966 93 644623523 312 553967887 448 714110036 391 129391856 52 673...
output:
366983664970984 383079448403030 259249033016629 14356472689640 371959435491179 481578275317316 15143...
result:
wrong answer 1st lines differ - expected: '173096624515978', found: '366983664970984'
Test #11:
score: 0
Wrong Answer
time: 234ms
memory: 512kb
input:
10 416394745 108 799849287 309 285823581 120 50495267 151 984269713 448 325585187 230 502469917 398 ...
output:
867768511507123 86049512841777 284725207855200 1260884688262553 243108486562269 917936192878781 7447...
result:
wrong answer 1st lines differ - expected: '510932724030159', found: '867768511507123'
Test #12:
score: 0
Wrong Answer
time: 195ms
memory: 508kb
input:
10 858503120 86 550141525 344 266071218 423 114926419 32 463189501 184 235629038 219 681438792 48 66...
output:
745420506012744 57899258458559 537809527520673 690168751572562 3221780898006845 329488467556591 2609...
result:
wrong answer 1st lines differ - expected: '1864662953909472', found: '745420506012744'
Test #13:
score: 0
Wrong Answer
time: 211ms
memory: 512kb
input:
10 49615553 235 484012586 439 733063300 215 529603390 181 217670208 264 477723402 451 412727927 119 ...
output:
315870876170210 918809358907097 132032712074864 236903676994216 1301323842264686 448957542022344 846...
result:
wrong answer 1st lines differ - expected: '163825824623411', found: '315870876170210'
Test #14:
score: 0
Wrong Answer
time: 216ms
memory: 508kb
input:
10 411060288 247 193494425 14 162692451 151 282497312 400 796796095 370 100991720 365 560074247 197 ...
output:
210117665846448 104739202907888 77794991315115 811471818129007 340178197803618 23957567974066 133735...
result:
wrong answer 1st lines differ - expected: '236839515269254', found: '210117665846448'
Test #15:
score: 0
Time Limit Exceeded
input:
10 733526255 46680 232614188 25143 740109721 35101 664765419 65813 926232187 19192 248710599 18813 7...
output:
result:
Test #16:
score: 0
Time Limit Exceeded
input:
10 40397805 9224 854461643 50758 463970290 6807 993317097 75888 496579182 67022 428873070 56575 8340...
output:
result:
Test #17:
score: 0
Time Limit Exceeded
input:
10 677231818 45638 135553472 57886 334073954 74682 504512612 32658 528899984 14506 658263816 15374 1...
output:
result:
Test #18:
score: 0
Time Limit Exceeded
input:
10 591761203 22205 53945697 65976 829627579 78277 112598137 27980 144133461 55044 668263637 96424 30...
output:
result:
Test #19:
score: 0
Time Limit Exceeded
input:
10 798158737 58985 625637387 56023 950567276 86709 613154552 23440 2676550 96868 636525260 84971 205...
output:
result:
Test #20:
score: 0
Time Limit Exceeded
input:
10 76769987 47758 832950079 87350 226318103 39942 857729326 28604 700759579 85249 4088534 87174 7300...