QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#760389 | #8143. Equations | thomaswmy | AC ✓ | 898ms | 3908kb | C++14 | 1.2kb | 2024-11-18 16:41:39 | 2024-11-18 16:41:41 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
const int N=1e6+10;
const int Mod=998244353;
const int inv2=(Mod+1)/2;
typedef long long ll;
int qpow(int x,ll y) {
int z=1;
for(;y;y>>=1) {
if(y&1) z=1ll*z*x%Mod;
x=1ll*x*x%Mod;
}
return z;
}
int gcd(int x,int y) {
if(!y) return x;
return gcd(y,x%y);
}
int exgcd(int a,int b,int &x,int &y) {
if(!b) {
x=1,y=0;
return a;
}
int z=exgcd(b,a%b,x,y);
int t=y;
y=x-a/b*y;
x=t;
return z;
}
int T;
ll n;
int a,b;
int solve(int a,int b,int p) {
b=(p+b%p)%p;
int g=gcd(a,p);
if(b%g) return 0;
int x,y;
exgcd(a,p,x,y);
x%=p/g;
if(x<0) x+=p/g;
x=(1ll*x*b/g)%(p/g);
return x;
}
int main() {
scanf("%d",&T);
while(T--) {
scanf("%lld%d%d",&n,&a,&b);
int ans=0;
for(int i=1;i<=min(n,(ll)b);i++) ans=(ans+solve(a%i,b%i,i))%Mod;
if(n>b) {
if(b%a==0) {
int x=b/a;
ans=(ans+(n-b)%Mod*x%Mod)%Mod;
}
else {
for(int i=b+1;i<=b+a && i<=n;i++) {
int z=solve(i,-b,a);
if(b%a && !z) continue;
ll f=(b+1ll*i*z)/a;
ll c=(n-i)/a+1;
ans=(ans+f%Mod*(c%Mod)%Mod+c%Mod*((c-1)%Mod)%Mod*inv2%Mod*z%Mod)%Mod;
}
}
}
printf("%d\n",ans);
}
return 0;
}
这程序好像有点Bug,我给组数据试试?
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3720kb
input:
5 5 4 3 5 3 4 10 5 8 10 8 5 100 79 97
output:
2 3 15 10 2519
result:
ok 5 lines
Test #2:
score: 0
Accepted
time: 33ms
memory: 3908kb
input:
5 10008 877729 253380 637 499618 249999 390830 696450 63937 75 585876 450454 474 619514 554172
output:
24318748 45506 208735371 550 31335
result:
ok 5 lines
Test #3:
score: 0
Accepted
time: 77ms
memory: 3756kb
input:
5 4 544128 393435 55208 121163 251280 95 667529 607099 9803 177176 454551 781518 644508 418918
output:
0 620844928 2252 11788364 728689092
result:
ok 5 lines
Test #4:
score: 0
Accepted
time: 27ms
memory: 3852kb
input:
5 242320 531990 145110 2 199500 833358 4464 641319 686329 7040 887048 182860 40 746882 749700
output:
541767887 0 2790683 8163116 143
result:
ok 5 lines
Test #5:
score: 0
Accepted
time: 2ms
memory: 3720kb
input:
5 23767 457425 107200 573 566400 149397 94 861696 793778 1703 482817 337806 79 509328 853951
output:
73828986 23787 862 532151 505
result:
ok 5 lines
Test #6:
score: 0
Accepted
time: 42ms
memory: 3788kb
input:
5 242940 377882 728961 48 449680 58068 46051 27321 854113 130144 446107 347090 79400 986217 323376
output:
390960494 236 302383824 98866535 176620786
result:
ok 5 lines
Test #7:
score: 0
Accepted
time: 557ms
memory: 3724kb
input:
5 670600637018491392 741826 766177 381745413883570905 40790 744016 646453202268579878 623731 531826 323647657649111080 303255 829755 307953872292809891 24831 779598
output:
908672499 81825153 455478625 523335218 466019786
result:
ok 5 lines
Test #8:
score: 0
Accepted
time: 400ms
memory: 3836kb
input:
5 147257310597328496 628355 686000 123542039462907690 698367 250251 984709196284970384 135840 534912 422986876614691368 68200 51464 415382184532240296 382968 34896
output:
343713591 305518252 537065154 333510764 783528610
result:
ok 5 lines
Test #9:
score: 0
Accepted
time: 432ms
memory: 3832kb
input:
5 797061848731948800 729751 536424 794642324102532356 538389 646140 201204532082235278 533520 676924 643600905335511144 63898 125442 32537838124946736 38640 220500
output:
286052461 538967772 214529608 303625548 593908135
result:
ok 5 lines
Test #10:
score: 0
Accepted
time: 609ms
memory: 3840kb
input:
5 362030744934681732 426489 704098 230109824011736484 169978 995565 107318731476083800 831203 752600 772767003335450005 45220 663424 372890423417854000 255809 971286
output:
264992638 937600835 549846159 53095118 211442630
result:
ok 5 lines
Test #11:
score: 0
Accepted
time: 457ms
memory: 3844kb
input:
5 383153378946695840 829134 390634 219233101482888470 155804 326407 920141956915691034 289845 594450 940170395139416756 386834 235255 537888931871483984 728335 446542
output:
803572863 492061418 31845307 983936720 506263937
result:
ok 5 lines
Test #12:
score: 0
Accepted
time: 562ms
memory: 3728kb
input:
5 344361424391917968 191104 864600 93095692328897622 110781 19683 230170744699450134 972599 786136 358790713525310000 530208 415280 74460882419810065 851280 292914
output:
238294388 776744920 347507174 101306910 517364462
result:
ok 5 lines
Test #13:
score: 0
Accepted
time: 563ms
memory: 3812kb
input:
5 978155661774442353 603824 630960 590100144252730144 848345 1380 317759285710668018 746790 120050 298479243163157760 67790 343032 156490273350831735 673295 914294
output:
266002283 735145369 347600423 2228348 970351496
result:
ok 5 lines
Test #14:
score: 0
Accepted
time: 469ms
memory: 3832kb
input:
5 604531522725511695 469944 599392 395043270301731744 612680 831941 52655090949443712 531267 782694 272355042956580000 203176 151890 702215752561618517 6912 834500
output:
37257776 451357034 414035099 430889935 859626359
result:
ok 5 lines
Test #15:
score: 0
Accepted
time: 367ms
memory: 3852kb
input:
5 264792084001292465 527184 440584 518557521492300312 155712 248394 694805468483146950 480768 48616 795313497305849019 502614 695866 35709765881428735 451500 292674
output:
713409665 696216350 817854538 158241661 653143854
result:
ok 5 lines
Test #16:
score: 0
Accepted
time: 429ms
memory: 3832kb
input:
5 172707539242069740 400250 421137 207321389880724691 197270 230574 143766706005088880 684256 81890 225472794975487773 829440 353122 192776602146671196 136034 963460
output:
391163105 498351937 116255203 253641990 292093011
result:
ok 5 lines
Test #17:
score: 0
Accepted
time: 420ms
memory: 3908kb
input:
5 230998041919503252 385419 2825 194277357326490624 214071 941016 624285222751766641 77675 142120 773152943008628440 334536 500291 135507241147746384 696807 668736
output:
318302937 754197461 752707270 370902386 750813070
result:
ok 5 lines
Test #18:
score: 0
Accepted
time: 539ms
memory: 3844kb
input:
5 487152847662578352 874044 336163 379185726542412224 106848 335525 244127527693437080 732569 279104 729577909147767680 768772 441000 189684529024684883 177142 923400
output:
55627683 653059642 679584254 872821412 549394086
result:
ok 5 lines
Test #19:
score: 0
Accepted
time: 413ms
memory: 3720kb
input:
5 646216676138111330 197182 614640 281768131598103360 69144 631955 158838836647773744 406764 151560 938247222815484076 892101 739293 547670910384768347 111176 29156
output:
605513738 558145201 81809639 300704831 878166319
result:
ok 5 lines
Test #20:
score: 0
Accepted
time: 567ms
memory: 3776kb
input:
5 657838271552672169 627396 144266 236977033945585232 612779 891544 37425647134359840 903960 74875 424412170161617890 977345 394444 558608609371822677 30603 575049
output:
979905170 916580724 174675029 988999733 719636524
result:
ok 5 lines
Test #21:
score: 0
Accepted
time: 512ms
memory: 3896kb
input:
5 292677265118859326 387904 970844 202729623657107976 781485 614888 825339609900331290 231660 769840 999929829142426712 323536 43650 380713715033870400 560736 770347
output:
382483686 624997358 694951006 315175 975551986
result:
ok 5 lines
Test #22:
score: 0
Accepted
time: 748ms
memory: 3840kb
input:
5 1145141919810 1000000 1000000 998244353998244853 999997 933333 233333333333333333 333333 666666 123123123123123123 999993 114514 188888888888888888 998245 663421
output:
155646870 184261055 533815097 11598912 395012492
result:
ok 5 lines
Test #23:
score: 0
Accepted
time: 898ms
memory: 3904kb
input:
5 999999999991919810 999993 284529 999999999999114514 999983 131313 999999999999999999 999979 177563 1000000000000000000 999969 634131 999999999987654321 999961 322334
output:
746433218 365266724 299503509 314482167 473683618
result:
ok 5 lines
Test #24:
score: 0
Accepted
time: 241ms
memory: 3836kb
input:
5 1 1 1 1000000000000000000 1000000 1 1000000000000000000 1 1000000 1000000000000000000 1 1 1000000000000000000 1000000 1000000
output:
0 435054597 361490945 716070897 716070849
result:
ok 5 lines
Test #25:
score: 0
Accepted
time: 159ms
memory: 3836kb
input:
1 998244353998244353 999997 100003
output:
127234402
result:
ok single line: '127234402'
Test #26:
score: 0
Accepted
time: 0ms
memory: 3836kb
input:
5 1 1000000 1000000 2 1 1 3 1 1 4 1 1 5 1 1
output:
0 1 2 3 4
result:
ok 5 lines
Extra Test:
score: 0
Extra Test Passed