QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#577290 | #1835. Fancy Formulas | xzf_200906 | WA | 51ms | 3616kb | C++14 | 687b | 2024-09-20 10:08:48 | 2024-09-20 10:08:49 |
Judging History
answer
#include <bits/stdc++.h>
#define LL long long
using namespace std;
int qp(int a,int b,int mod){
int ret=1;
while(b){
if(b&1) ret=1ll*ret*a%mod;
a=1ll*a*a%mod;
b>>=1;
}
return ret;
}
signed main(){
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int p,T;
cin>>p>>T;
while(T--){
int a,b,c,d;
cin>>a>>b>>c>>d;
if((a+b)%p!=(c+d)%p){
cout<<"-1\n";
continue;
}
if(a==c&&b==d){
cout<<"0\n";
continue;
}
int val=((-(a+b))%p+p)%p;
for(int k=1;;k++){
int num=((c-1ll*qp(2,k,p)*a)%p+p)%p;
int stp=1ll*qp(val,p-2,p)*num%p;
if(stp<=(1ll<<(k-1))){
cout<<k<<'\n';
break;
}
}
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3616kb
input:
5 10 2 1 3 0 2 1 4 4 1 3 4 0 0 2 0 4 3 3 1 2 0 1 0 1 0 3 0 3 0 1 0 1 1 2 4 4 1 0 1 1
output:
2 1 2 -1 -1 0 0 0 1 -1
result:
ok 10 numbers
Test #2:
score: -100
Wrong Answer
time: 51ms
memory: 3580kb
input:
97 100000 30 56 74 12 95 39 8 29 11 42 76 74 48 63 58 53 74 22 85 11 80 23 84 4 30 90 30 90 92 91 41 45 21 82 11 92 65 30 28 67 74 57 95 36 16 31 78 66 2 77 6 73 83 20 41 62 45 44 92 94 96 28 77 47 76 12 87 1 47 80 42 85 46 91 65 72 23 39 4 58 21 96 37 80 83 33 66 50 84 21 61 44 4 78 47 35 39 50 39 ...
output:
7 8 6 7 6 -1 0 6 6 7 7 6 6 2 7 8 8 7 7 7 6 8 5 3 0 5 5 8 6 6 7 5 7 5 5 7 7 -1 5 4 -1 8 4 -1 6 8 5 5 -1 6 6 8 0 -1 2 -1 5 -1 5 7 2 7 6 6 6 6 -1 6 8 6 7 7 6 -1 4 2 8 0 7 -1 7 7 -1 4 7 8 -1 8 3 5 0 -1 7 3 4 6 7 6 0 1 7 7 6 -1 -1 -1 6 5 7 6 6 3 5 -1 -1 2 3 5 6 -1 -1 7 -1 5 7 8 5 8 -1 3 5 5 -1 4 5 6 -1 7...
result:
wrong answer 1st numbers differ - expected: '6', found: '7'