QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#28300#1835. Fancy FormulasSenioriousWA 57ms3844kbC++17908b2022-04-13 11:08:082022-04-29 09:33:54

Judging History

你现在查看的是最新测评结果

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-04-29 09:33:54]
  • 评测
  • 测评结果:WA
  • 用时:57ms
  • 内存:3844kb
  • [2022-04-13 11:08:08]
  • 提交

answer

#include <bits/stdc++.h>

#define File(a) freopen(a ".in", "r", stdin), freopen(a ".out", "w", stdout)

using ll = long long;

int pow(int a, int b, int ans = 1);

int p, T;

int main() {
  scanf("%d %d", &p, &T);
  while (T--) {
    int a, b, c, d;
    scanf("%d %d %d %d", &a, &b, &c, &d);
    if ((a + b) % p != (c + d) % p) {
      puts("-1");
      continue;
    }
    int s = pow(a + b, p - 2);
    a = 1ll * a * s % p, b = 1ll * b * s % p;
    c = 1ll * c * s % p, d = 1ll * d * s % p;
    for (int k = 0; k <= 30; ++k) {
      ll L = ((ll)(a - 1) << k), R = (ll)a << k;
      L = L + p - c, R = R + p - c;
      if ((R / p) != (L / p)) {
        printf("%d\n", k);
        break;
      }
    }
  }
  return 0;
}

int pow(int a, int b, int ans) {
  while (b) {
    if (b & 1) ans = 1ll * ans * a % p;
    a = 1ll * a * a % p;
    b >>= 1;
  }
  return ans;
}

详细

Test #1:

score: 100
Accepted
time: 3ms
memory: 3844kb

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: 57ms
memory: 3772kb

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 316th numbers differ - expected: '6', found: '8'