QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#410544 | #1835. Fancy Formulas | iee# | WA | 31ms | 3580kb | C++17 | 742b | 2024-05-14 09:06:07 | 2024-05-14 09:06:08 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
int power(int a, int b, int P) {
int res = 1;
while (b) {
if (b & 1) res = 1ll * res * a % P;
a = 1ll * a * a % P;
b /= 2;
}
return res;
}
int P;
int main() {
cin.tie(0)->sync_with_stdio(0);
int Q;
cin >> P >> Q;
while (Q--) {
int a, b, c, d;
cin >> a >> b >> c >> d;
if ((a + b) % P != (c + d) % P) {
cout << -1 << "\n";
continue;
}
const int inv = power((a + b) % P, P - 2, P);
if (!a) {
cout << 1ll * (a - c + P) % P * inv % P << "\n";
continue;
}
for (int i = 0, j = a; ; i++, j = j * 2 % P) {
int D = (j - c + P) % P;
if (1ll * D * inv % P <= i) {
cout << i << "\n";
break;
}
}
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3528kb
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: 31ms
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:
20 15 7 12 6 -1 0 16 8 10 12 8 6 2 12 15 9 19 14 13 11 8 5 3 0 12 9 17 8 10 8 13 22 7 19 13 9 -1 9 4 -1 12 13 -1 17 11 5 5 -1 6 7 13 0 -1 2 -1 10 -1 5 14 2 9 14 17 6 20 -1 10 13 16 15 7 15 -1 4 2 18 0 14 -1 8 8 -1 4 7 12 -1 15 3 11 0 -1 10 3 4 12 7 7 0 1 15 17 13 -1 -1 -1 11 5 16 9 7 8 5 -1 -1 2 3 5...
result:
wrong answer 1st numbers differ - expected: '6', found: '20'