QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#692793 | #1835. Fancy Formulas | OOBMABTRAMS# | WA | 59ms | 3700kb | C++14 | 909b | 2024-10-31 15:03:28 | 2024-10-31 15:03:28 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int P=998244353;
const int N=1200103;
ll f[N],a[N],pw[N];
ll p,q;
ll iv(ll x){return x==1?1:(p-p/x)*iv(p%x)%p;}
void solve(){
cin>>p>>q;
for(int i=pw[0]=1;i<=32;i++)pw[i]=pw[i-1]*2;
while(q--) {
ll a,b,c,d;
cin>>a>>b>>c>>d;
if((a+b)%p!=(c+d)%p){
cout<<-1<<'\n';
}else {
//a t-a
ll t=(a+b)%p;
int ans=-1;
for(int i=0;i<=32;i++) {
//a=1 t=3 d=4
//2*(1+4)
if(iv(t)*(pw[i]*a%p+d)%p<=pw[i]&&iv(t)*(pw[i]*a%p+d)%p>=1) {
ans=i;
break;
}
}
cout<<ans<<'\n';
}
}
}
int main(){
ios::sync_with_stdio(false);
int T=1;
//cin>>T;
while(T--)solve();
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3584kb
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: 59ms
memory: 3700kb
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:
6 6 5 6 6 -1 0 4 6 7 7 6 6 2 7 7 6 7 6 4 6 5 5 3 0 4 5 6 6 5 5 5 6 5 5 6 7 -1 5 4 -1 6 4 -1 4 6 5 5 -1 6 6 7 0 -1 2 -1 5 -1 5 7 2 4 6 4 6 6 -1 6 7 6 6 7 6 -1 4 2 7 0 6 -1 6 2 -1 4 6 5 -1 7 3 5 0 -1 7 3 4 6 4 6 0 1 5 7 6 -1 -1 -1 6 5 5 5 3 3 3 -1 -1 2 3 5 6 -1 -1 7 -1 5 7 6 5 6 -1 3 5 5 -1 4 5 6 -1 6...
result:
wrong answer 418th numbers differ - expected: '7', found: '8'