QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#810456 | #7230. Fraction Factory | Aurore | TL | 2710ms | 5916kb | C++23 | 1.4kb | 2024-12-11 22:49:34 | 2024-12-11 22:49:34 |
Judging History
answer
#include<bits/stdc++.h>
#define int __int128
#define pr(x,y) make_pair(x,y)
using namespace std;
inline int read(){
int x=0,f=1;char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')f=-f;ch=getchar();}
while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
return x*f;
}
int buf[105];
inline void print(int x,char ch=' '){
if(x<0) putchar('-'),x=-x;
int tot=0;
do{
buf[++tot]=x%10;
x/=10;
}while(x);
for(int i=tot;i;i--) putchar(buf[i]+'0');
putchar(ch);
}
const int MAXN=1e6+5;
int exgcd(int a,int b,int &x,int &y){
if(!b){
x=1,y=0;
return a;
}
int ans,p,q;
ans=exgcd(b,a%b,p,q);
x=q;
y=p-a/b*q;
return ans;
}
int inv(int a,int b){
int x,y;
exgcd(a,b,x,y);
return (x%b+b)%b;
}
int gcd(int a,int b){
while(b){
a=a%b;
swap(a,b);
}
return a;
}
int n,m,a[MAXN],b[MAXN];
signed main(){
n=read(),m=read();
for(int i=1;i<=n;i++) a[i]=read();
for(int i=1;i<=m;i++){
b[i]=read();
for(int j=1;j<=n;j++){
int d=gcd(a[j],b[i]);
a[j]/=d,b[i]/=d;
}
}
int T=read();
while(T--){
int mod=read();
int A=1,B=1;
for(int i=1;i<=n;i++) A=A*a[i]%mod;
bool flag=1;
for(int i=1;i<=m;i++)
if(gcd(b[i],mod)!=1) flag=0;
if(!flag){
cout<<"DIVISION BY ZERO\n";
}
else{
for(int i=1;i<=m;i++) B=B*b[i]%mod;
B=inv(B,mod);
print(A*B%mod,'\n');
}
}
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 5652kb
input:
3 2 8 11 14 9 12 4 8 9 10 11
output:
4 DIVISION BY ZERO 4 0
result:
ok 4 lines
Test #2:
score: 0
Accepted
time: 1ms
memory: 5640kb
input:
2 2 1 2 4 3 10 5 7 11 13 17 19 23 29 31 37
output:
1 6 2 11 3 16 4 5 26 31
result:
ok 10 lines
Test #3:
score: 0
Accepted
time: 1ms
memory: 5644kb
input:
4 6 111111111111111111 1000000000000000000 1000000000000000 135792468013579246 10000000000000000 100000000000000 999999999999999999 123456789123456789 239239239932932932 1357924680 10 1161978962132362 539566136338457734 758923339452654441 655309120486827715 84306884606421160 911731869459297905 82243...
output:
DIVISION BY ZERO DIVISION BY ZERO DIVISION BY ZERO 5719954405760135 DIVISION BY ZERO 892796932685565430 DIVISION BY ZERO DIVISION BY ZERO DIVISION BY ZERO DIVISION BY ZERO
result:
ok 10 lines
Test #4:
score: 0
Accepted
time: 1ms
memory: 5556kb
input:
8 5 1 1 1 1 1 1 1 1 1 1 1 1 1 33 519802560097260385 442596183335011282 688602833488446065 473642221531625139 336139490404077831 411067731885836516 348529798548197702 559996805776212339 324766630988403651 740258357792871391 670233519941996489 131286432198704669 193327986539006166 922036187121404691 2...
output:
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
result:
ok 33 lines
Test #5:
score: 0
Accepted
time: 1ms
memory: 5588kb
input:
2 1 999999929 999999937 999999937 3 999999929 999999937 999999866000004473
output:
0 999999929 999999929
result:
ok 3 lines
Test #6:
score: 0
Accepted
time: 1ms
memory: 5876kb
input:
20 20 598463 808739 504181 886643 804161 162703 42409 66179 479599 14939 435103 1278181 484019 1177019 553171 763423 1098221 628939 863377 130349 291877 228847 1150139 1008017 1057853 312107 818371 226643 446309 629569 142223 517373 90989 415073 120749 1075619 1058041 893653 454919 25747 50 1299899 ...
output:
602146 881975 266900 136515 266900 1071154 693499 244967 1060614 977384 26884 364814 850337 787165 919943 635052 482194 601195 841086 266212 754504 1079624 458235 34996 26072 865453 391778 406195 930981 78961 1104083 65599 602146 161608 949246 1267514 1071154 678271 220844 602955 244967 967494 22860...
result:
ok 50 lines
Test #7:
score: 0
Accepted
time: 20ms
memory: 5852kb
input:
500 500 387371 1004137 65647 352021 112069 456623 45863 104911 687151 522061 1042183 57991 428801 1110817 45263 961871 134443 376589 395377 161459 886381 1085753 674761 729041 444007 1218449 309937 594179 58049 10453 88117 434933 1177619 1086703 572087 675629 387791 640621 547453 594421 657313 12257...
output:
383179 888275 182734 185609 872863 59626 837128 391943 1194073 750514 634775 775567 1239102 407018 987868 695749 777370 215628 412673 272425 775567 1221783 1200408 775567 845048 827229 426950 838606 845048 626180 739737 383179 925291 998734 591167 870060 591167 845048 775567 964211 775567 592363 998...
result:
ok 50 lines
Test #8:
score: 0
Accepted
time: 2036ms
memory: 5916kb
input:
5000 5000 46237 985451 469367 284423 516653 397469 1143269 530183 1181183 330641 410353 101561 22067 686837 488339 1044697 711523 1042399 1092331 915697 1089047 1004527 1181923 1297421 865771 785207 833179 1046701 1138867 431077 1146709 1159127 419249 876041 486091 616799 301901 504001 889703 601189...
output:
815409 894989 6379 492271 185760 75492 1221630 1228920 878065 15324 78386 1219609 1238304 1241440 1010201 1203934 978181 944584 1010201 787803 244893 464400 583569 95906 45296 721934 518863 1286321 48086 798733 78386 271489 99969 221437 383353 1290376 908368 1078270 407153 815409 818442 177234 10650...
result:
ok 50 lines
Test #9:
score: 0
Accepted
time: 1973ms
memory: 5664kb
input:
4843 4989 282311 1224131 288947 1381 708733 832957 592507 193441 643073 625763 197293 951781 993841 1247581 908377 1164409 820429 1131769 544199 1089133 362951 1139407 504983 453157 668141 1191947 666697 1182767 17317 825107 1051319 275083 415687 166669 1244357 287863 891647 135463 1194581 782263 22...
output:
686206 64764 587541 854266 1047316 142248 1037628 919664 699909 889977 519197 830228 170110 451078 273750 691678 284952 830228 370585 380037 1278741 1022439 336430 258606 1047316 15133 298290 188086 273750 760625 911592 759463 862385 297412 144024 164772 442621 885396 1014203 316106 919664 171896 60...
result:
ok 50 lines
Test #10:
score: 0
Accepted
time: 1ms
memory: 5872kb
input:
1 1 999999999426987301 999999999446177371 50 999999999230595023 999999999459528149 999999999055719173 999999999347239897 999999999080279609 999999999817973431 999999999308902993 999999999390597539 999999999416910001 999999999447428923 999999999004310363 999999999974038457 999999999094972633 99999999...
output:
756632012721641517 457106544405250940 440266340208005663 324513075591986058 499343753384200875 985938662000008459 744506450645645896 739813282899850512 783165688841699050 3322275061445653 640237529836849823 14791088426240426 91526031664494402 122173425113395265 135014011813139239 272785455764605788 ...
result:
ok 50 lines
Test #11:
score: 0
Accepted
time: 2ms
memory: 5844kb
input:
111 55 999999999437952739 999999999727121671 999999999952083791 999999999603858779 999999999035103917 999999999148643791 999999999192594061 999999999300412063 999999999128184707 999999999464910839 999999999460599923 999999999870821689 999999999980529061 999999999601005607 999999999211292561 99999999...
output:
708901826487331864 968740921462851986 528434535223783010 925628093565076668 526894146655099327 727396951083284217 45912440578684688 480612489151189098 504337517746168956 294993557461828069 560169763847527076 277064786474648892 321763466459407739 109945913705886746 988379719199747304 1569602508498478...
result:
ok 50 lines
Test #12:
score: 0
Accepted
time: 94ms
memory: 5656kb
input:
617 1172 999999999422370301 999999999279606739 999999999378912107 999999999364760257 999999999451911457 999999999938125993 999999999975745057 999999999065716031 999999999100397237 999999999530841719 999999999401480507 999999999238898551 999999999569670571 999999999560191109 999999999220028347 999999...
output:
824586476778382647 478890352822045637 686218461446538755 502090793279450771 394983069806446996 923532826225112601 864465032116294624 779905508741707265 903087500023092787 428436909658805039 239470801026877319 300887758894243769 349742234633818613 84753050449013963 56049586974938995 12135540187201907...
result:
ok 50 lines
Test #13:
score: 0
Accepted
time: 2710ms
memory: 5888kb
input:
4494 4920 999999999067434397 999999999269373331 999999999907980557 999999999530340857 999999999124595467 999999999168087251 999999999730737389 999999999331612633 999999999279031469 999999999328851233 999999999831783637 999999999543585427 999999999133465261 999999999667696567 999999999175495691 99999...
output:
198935648876742382 694325433912839534 351254060755570076 831073884976136269 407353710233817702 338238026247663782 306378523377933445 818714774356353280 906243522491418926 867399791448174488 707273994099362460 708101482059544384 87038106095552003 194318080401319673 298181879329306649 6552434725303427...
result:
ok 50 lines
Test #14:
score: -100
Time Limit Exceeded
input:
5000 5000 999999999280582667 999999999430144927 999999999621742387 999999999735098749 999999999864759527 999999999270579247 999999999495623849 999999999764228761 999999999168685303 999999999274868833 999999999420287267 999999999023317709 999999999050968213 999999999048439217 999999999596454203 99999...
output:
113776408893401412 749914750049534368 181644927923148832 799557251986405560 407976607821476607 412756092597615130 757821607726535946 311667021889869068 288950617997452359 770805464527200602 351892137846000340 607041955547440541 803186803439143161 236009152289366873 633055553846381543 738952398532960...