QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#420577 | #8706. 解方程 | Williamxzh | 0 | 1695ms | 3744kb | C++23 | 1.9kb | 2024-05-24 20:22:00 | 2024-05-24 20:22:00 |
Judging History
answer
#include <bits/stdc++.h>
#define il inline
#define B __int128
using namespace std;
il B read(){
B x=0,c=getchar();
while(!isdigit(c)) c=getchar();
while(isdigit(c)) x=x*10+c-48,c=getchar();
return x;
}
void write(B x){
if(x>9) write(x/10);
putchar(x%10+48);
}
il void print(B x,char c){write(x),putchar(c);}
il B qp(B a,B b,B mod){
B ans=B(1);
while(b){
if(b&1) ans=(ans*a)%mod;
a=(a*a)%mod,b>>=1;
}
return ans;
}
const int N=10;const B inf=1e6;
int T,n,ck;B p,m,a[N],b[N],c[N],cur[N],iv[N],ans;
B x,y,z,u,v,w,s,t;
int main(){
scanf("%d",&T);
while(T--){
scanf("%d",&n);p=read(),m=B(sqrtl(p)),ans=0;
for(int i=1;i<=n;++i) a[i]=read(),b[i]=read(),c[i]=read(),iv[i]=qp(a[i]+1,p-2,p);
for(B i=min(inf,m);i;--i){
ck=1;for(int j=1;j<=1;++j) cur[j]=(c[j]-a[j]*i%p*i%p+p)%p*iv[j]%p;
//for(int j=1;j<=n;++j) if((a[j]*(i*i+cur[j])%p+cur[j])%p!=c[j]) puts("*");
x=y=cur[1];
for(int j=2;j<=n;++j){
y=(x*y)%i;
if(((a[j]*(i*i+x)%p+y)%p)!=c[j]){ck=0;break;}
}
if(ck && i*i+cur[1]<p){ans=i*i+cur[1];break;}
ck=1;for(int j=1;j<=1;++j) cur[j]=(c[j]-a[j]*i%p*(i+1)%p+p)%p*iv[j]%p;
x=y=cur[1];
for(int j=2;j<=n;++j){
y=(x*y)%i;
if(((a[j]*(i*i+x)%p+y)%p)!=c[j]){ck=0;break;}
}
if(ck && i*i+cur[1]+i<p){ans=i*i+cur[1]+i;break;}
ck=1;x=i*i+B(2)*i;
for(int j=1;j<=n;++j) if((a[j]*x%p)!=c[j]){ck=0;break;}
if(ck && i*i+i*2<p){ans=i*i+2*i;break;}
}
print(ans,'\n');
}
return 0;
}
/*
1
5 923097614961380909
400075690252081333 1 336925156808111277
125871709464257940 1 69865713802049054
625686524906165721 1 231604442249496820
240111021937539825 1 466914943115931347
877342215923645363 1 405475742085577903
*/
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 0
Wrong Answer
time: 1695ms
memory: 3744kb
input:
40 5 923097614961380909 400075690252081333 1 336925156808111277 125871709464257940 1 69865713802049054 625686524906165721 1 231604442249496820 240111021937539825 1 466914943115931347 877342215923645363 1 405475742085577903 5 954878053655579819 314356765890269968 1 479476497512555507 3066762309305691...
output:
105920391906 0 0 454985828211 684359412322 0 843969628814 0 969809963928 839021293810 0 0 0 878033311810 0 0 657591767649 0 0 0 0 697228408265 379537727517 165129354629 0 0 632214523300 336727638633 0 654447474609 786554741772 0 0 0 398155998800 340946229446 0 933504007728 971392574522 0
result:
wrong answer 2nd lines differ - expected: '517298493095', found: '0'
Subtask #2:
score: 0
Time Limit Exceeded
Test #2:
score: 0
Time Limit Exceeded
input:
40 5 923097614961380909 400075690252081333 1 36226200850654830 125871709464257940 1 801294848271831 625686524906165721 1 167289389520696370 240111021937539825 1 566782367688890103 877342215923645363 1 437769344508562455 5 954878053655579819 314356765890269968 1 481049707495526324 306676230930569168 ...
output:
result:
Subtask #3:
score: 0
Time Limit Exceeded
Test #3:
score: 0
Time Limit Exceeded
input:
40 5 923097614961380909 400075690252081333 1 167001433276774274 125871709464257940 1 775646046137144068 625686524906165721 1 792747143363812162 240111021937539825 1 511005265275196004 877342215923645363 1 898824348527556482 5 954878053655579819 314356765890269968 1 501561843363742850 306676230930569...
output:
result:
Subtask #4:
score: 0
Time Limit Exceeded
Test #4:
score: 0
Time Limit Exceeded
input:
40 5 923097614961380909 400075690252081333 1 711217741985470914 125871709464257940 1 444725029628910905 625686524906165721 1 74716258575747726 240111021937539825 1 409246477245810521 877342215923645363 1 369189987866325821 5 954878053655579819 314356765890269968 1 80576853778385871 30667623093056916...
output:
result:
Subtask #5:
score: 0
Time Limit Exceeded
Test #5:
score: 0
Time Limit Exceeded
input:
40 5 923097614961380909 400075690252081333 6 711217743785736202 125871709464257940 6 444725031004785657 625686524906165721 3 74716259410497736 240111021937539825 9 409246477844369931 877342215923645363 10 369189993610199341 5 954878053655579819 314356765890269968 5 80576853778385871 3066762309305691...
output:
result:
Subtask #6:
score: 0
Time Limit Exceeded
Test #6:
score: 0
Time Limit Exceeded
input:
40 5 923097614961380909 400075690252081333 95 711217768089317590 125871709464257940 95 444725049579094809 625686524906165721 98 74716266923247826 240111021937539825 92 409246509568018661 877342215923645363 91 369190035253282361 5 954878053655579819 314356765890269968 96 80576904711097456 30667623093...