QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#355502 | #8111. Coaches | ucup-team004 | AC ✓ | 82ms | 3688kb | C++20 | 1.8kb | 2024-03-16 18:44:02 | 2024-03-16 18:44:03 |
Judging History
answer
#include <bits/stdc++.h>
using i64 = long long;
i64 f(i64 a, i64 b, i64 l, i64 r) {
if (l == 0) {
return 0;
}
if (a == 0) {
return -1;
}
i64 v = (l + a - 1) / a;
if (v * a <= r) {
return v;
}
v = f(b % a, a, a - r % a, a - l % a);
if (v == -1) {
return -1;
}
return (v * b + l + a - 1) / a;
}
bool get1(i64 a, i64 x, i64 n, i64 b, i64 y) {
if (x >= n) {
return false;
}
if (y == 0) {
return true;
}
i64 l = (y - x % b + b) % b;
i64 r = (-x % b + b) % b;
i64 k = (n - 1 - x) / a;
if (l < r) {
i64 v = f(a, b, l, r - 1);
if (v != -1 && v <= k) {
return true;
}
} else {
if (l < b) {
i64 v = f(a, b, l, b - 1);
if (v != -1 && v <= k) {
return true;
}
}
if (r > 0) {
i64 v = f(a, b, 0, r - 1);
if (v != -1 && v <= k) {
return true;
}
}
}
return false;
}
i64 get(i64 n, int a, int b) {
int g = std::gcd(a, b);
if (g != 1) {
return get(n / g, a / g, b / g);
}
i64 res = n / a + n / b - 2 * (n / a / b);
i64 na = n % a;
i64 nb = n % b;
i64 nab = n % (1LL * a * b);
if (na < nab || nb < nab) {
res--;
}
if (get1(a, na, nab, b, nb)
|| get1(b, nb, nab, a, na)) {
res--;
}
return res;
}
void solve() {
i64 n;
int a, b;
std::cin >> n >> a >> b;
i64 bad = get(n, a, b);
std::cout << n - bad << "\n";
}
int main() {
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
int t;
std::cin >> t;
while (t--) {
solve();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3576kb
input:
2 5 2 3 10 7 2
output:
3 6
result:
ok 2 number(s): "3 6"
Test #2:
score: 0
Accepted
time: 1ms
memory: 3688kb
input:
1728 7 6 3 10 12 1 6 2 7 8 4 10 11 10 5 1 6 8 3 3 5 9 2 6 11 1 5 1 1 8 7 3 6 6 10 9 2 1 7 3 4 7 8 3 4 4 5 9 9 4 3 6 2 8 11 4 1 6 8 4 11 1 8 9 11 2 9 6 1 5 3 8 7 1 8 7 11 12 3 9 1 2 12 6 7 2 6 5 11 10 9 5 3 3 6 2 7 5 5 12 4 3 7 8 2 8 11 11 10 1 10 5 1 7 9 1 7 8 1 6 8 4 6 5 5 11 12 3 7 3 6 8 6 3 11 6 ...
output:
6 1 4 7 10 1 3 7 3 1 6 6 1 3 6 4 6 4 3 6 2 6 2 5 1 7 1 2 5 5 7 3 7 7 5 8 1 1 2 2 7 5 9 3 5 4 11 3 1 1 12 3 7 1 5 5 12 2 10 1 9 5 1 2 10 6 3 12 1 12 10 6 1 7 2 5 10 7 11 9 2 3 1 6 9 8 2 5 3 3 10 1 9 11 2 8 8 7 7 9 3 1 2 3 1 3 3 9 4 6 8 1 12 6 3 10 1 1 9 12 6 1 9 11 1 6 2 3 12 7 6 6 9 11 9 1 2 5 2 4 4...
result:
ok 1728 numbers
Test #3:
score: 0
Accepted
time: 20ms
memory: 3668kb
input:
97336 24 2 23 23 31 33 11 38 46 13 19 11 44 45 5 41 37 42 44 16 29 31 33 17 34 26 39 16 17 20 42 15 36 30 10 2 37 42 3 1 41 45 10 9 5 8 33 5 21 44 8 2 30 15 42 32 32 19 22 43 22 46 5 34 1 30 12 4 12 23 43 6 42 2 39 16 38 20 16 19 5 43 8 13 11 24 4 41 20 31 29 42 31 42 13 41 39 5 25 10 11 1 39 35 32 ...
output:
13 23 11 13 37 41 43 31 34 16 41 18 26 1 9 8 20 2 42 19 19 2 10 21 22 16 14 37 10 40 29 40 34 1 39 42 18 44 34 9 26 16 3 13 1 19 17 10 23 16 39 1 36 18 7 18 24 32 43 15 30 37 18 3 26 6 34 16 38 15 2 1 33 10 18 22 27 39 11 18 38 23 16 37 3 2 11 6 31 27 23 2 40 25 18 11 25 3 5 8 33 11 39 16 43 39 16 3...
result:
ok 97336 numbers
Test #4:
score: 0
Accepted
time: 47ms
memory: 3584kb
input:
100000 966978666727677953 103918709 172613701 10920141851516267 913419476 759905842 389768569272538945 536330283 640934149 639943523831961729 54166927 577019962 485205681543406081 198757 194331968 724016335198693249 813785681 961648601 939574367774573953 691820835 334275070 995545187588710401 304141...
output:
966978651820551992 10920141825190649 389768567937680831 639943510908627380 485203237846174806 724016333556113299 939574363605673886 995544858080726257 962654120619289539 812225197111279427 90146032962073878 73289302631177878 329554678347820923 761367689240413661 980502948980942906 937169598890548513...
result:
ok 100000 numbers
Test #5:
score: 0
Accepted
time: 57ms
memory: 3640kb
input:
100000 1 381430977 960300601 686256692528718785 719055657 477193028 60578768596646331 46270321 87282398 402833229164491391 592176716 680258474 344840919482871306 254943231 676309228 11 500382582 783671905 122537283958788406 714103482 514787928 838360371006965443 314021286 889918835 1 719894397 38792...
output:
1 686256690136221421 60578766593355578 402833227892056205 344840917620366394 11 122537283549157942 838360367395145086 1 219954563067525991 998298806906957815 25 456255445850206934 20 681242361213592899 565821008805097290 106552742182169048 1 676030455668184427 930241736559223929 696661014588743445 1...
result:
ok 100000 numbers
Test #6:
score: 0
Accepted
time: 32ms
memory: 3604kb
input:
100000 412694911046191617 109752726 4 611885622188585345 527624909 3 896125789270161921 8 99119385 336971263096778689 73023810 10 332408337631891137 3 272347821 690095136763649025 6 928269275 989053762600278401 3 641252028 624584537960286209 9 149144001 324081096302027777 65052370 7 2660893287906241...
output:
309521183284643714 407923747739157521 784110058830736799 303274141401640423 221605559641789479 575079280140760000 659369176609231426 555186254568767106 277783793271845824 236523847521939517 314851824398218258 343971228649014708 689715700962567864 311330498532235855 800075302806673431 217075785 34101...
result:
ok 100000 numbers
Test #7:
score: 0
Accepted
time: 59ms
memory: 3684kb
input:
100000 646168281515469471 907073078 712366127 350005794234520440 402860261 434400992 706442385900354482 527763828 2530355 231242443022789043 277983235 831857513 399652206725081961 515486014 516861364 376146063967850921 491111515 382953822 969909291308124631 888358010 72786649 296583103783161473 3827...
output:
646168279896029905 350005792559997938 706442105374732730 231242441912948297 399652205176560900 376146062219720251 969909276890951042 296583102625569709 140852066830 777266970812457060 810215314658277123 445803064128922917 709016677511173552 312279029846333384 779357205011564079 260879613855718246 36...
result:
ok 100000 numbers
Test #8:
score: 0
Accepted
time: 82ms
memory: 3664kb
input:
100000 225460217626744127 557209762 870186416 610267001328952640 791506150 98721779 728357584208964331 454255338 437293656 645987419091889616 721402572 201679105 367823654016344051 291886848 866358878 674138185634585137 274332202 830180790 54105256764732444 293820193 294557899 313948223101126477 139...
output:
225460216963026376 610266994376247130 728357580939951398 645987414993383407 367823652331623060 674138182365168371 54105256396905416 313948220021060809 515032764026701301 96904656382027210 976827210727652187 997327910039187510 632164030058701877 797043083941063921 813177343257136015 54876712287493458...
result:
ok 100000 numbers
Test #9:
score: 0
Accepted
time: 43ms
memory: 3564kb
input:
100000 836225652439333249 407343793 407343815 425408333379120129 457236645 457236611 34478270740365457 163933429 163933449 272153003480119073 908716947 908716968 971727704349973761 707912952 707912944 584543018096777985 148730276 148730249 252352089644180769 143384639 143384620 642002895462979329 73...
output:
836225648333584534 425408331518340368 34478270319728026 272153002881136078 971727701604642727 584543010236333121 252352086124248562 642002893709503616 315979739562945947 621815376473294344 620745054608522223 147008700678525149 660376051738932295 329180076476900633 633059505319307307 2906116086793843...
result:
ok 100000 numbers
Test #10:
score: 0
Accepted
time: 55ms
memory: 3572kb
input:
100000 641336008922806293 980690892 980716638 851037127616758823 787261833 884460339 241191156720236719 655921360 735426980 843470223383521925 479622072 959244150 591200481725778527 877459696 125351384 335226135532923714 875346312 437673160 870619200792200990 795708016 795741136 948647720074086453 9...
output:
641336007614896553 851037125573539231 241191156024562502 843470220745600540 591200476335669060 335226134384031700 870619198603958451 948647717969814441 724325943933593481 146662165566346104 703119208132083149 541526959523620396 875423773754095648 202211255174839180 799447511172307460 242715430849325...
result:
ok 100000 numbers
Test #11:
score: 0
Accepted
time: 55ms
memory: 3688kb
input:
100000 633278629651836090 918896895 689172673 731046751165142673 909690492 181951212 122803560711601149 372362726 744725451 524801408063966152 908106958 908139639 423228671762070226 704477776 657512592 905242446231077873 797186745 797186760 445869393605864795 313484600 940453780 90647237063555997 33...
output:
633278628043766536 731046746343703947 122803560216907864 524801406908172877 423228670517619414 905242443959985370 445869391709463797 90647236657531877 946118466858920456 938177972813959311 807204934031519595 915594390683195164 614138234001860291 711378773077785034 437844512321814183 4258287464633752...
result:
ok 100000 numbers