QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#743805#1835. Fancy Formulasocharin#WA 26ms3712kbC++201.4kb2024-11-13 20:04:272024-11-13 20:04:29

Judging History

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

  • [2024-11-13 20:04:29]
  • 评测
  • 测评结果:WA
  • 用时:26ms
  • 内存:3712kb
  • [2024-11-13 20:04:27]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;

#define int long long

void solve() {
    int p, q;
    std::cin >> p >> q;

    auto qpow = [&](int x, int y) {
        int ans = 1;
        while (y) {
            if (y & 1) {
                ans *= x;
                ans %= p;
            }
            x *= x;
            x %= p;
            y /= 2;
        }
        return ans;
    };

    for (int i = 1; i <= q; i++) {
        int base = 2;
        int a, b, c, d;
        std::cin >> a >> b >> c >> d;
        if ((a + b) % p != (c + d) % p) {
            std::cout << -1 << '\n';
            continue;
        }
        int inv = qpow(a + b, p - 2);

        if (a == c && b == d) {
            std::cout << 0 << '\n';
            continue;
        }

        for (int j = 1; j <= 40; j++) {
            int now = a * base % p;
            int cha = (now - c + p) % p;

            int ans = cha * inv % p;

            // std::cout << now << " " << cha << ' ' << ans << '\n';

            if (ans < base) {
                std::cout << j << '\n';
                break;
            }

            base *= 2;
            if(base >= p) {
                std::cout << i << '\n';
                break;
            }
        }
    }
}

signed main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);

    int t = 1;
    // std::cin >> t;

    while(t --) {
        solve();
    }
}

详细

Test #1:

score: 100
Accepted
time: 0ms
memory: 3612kb

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: 26ms
memory: 3712kb

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
10
11
6
6
2
15
16
6
18
6
4
6
5
5
3
0
4
5
6
6
5
5
5
6
5
5
6
37
-1
5
4
-1
6
4
-1
4
6
5
5
-1
6
6
52
0
-1
2
-1
5
-1
5
60
2
4
6
4
6
6
-1
6
69
6
6
72
6
-1
4
2
77
0
6
-1
6
2
-1
4
6
5
-1
88
3
5
0
-1
93
3
4
6
4
6
0
1
5
102
6
-1
-1
-1
6
5
5
5
3
3
3
-1
-1
2
3
5
6
-1
-1
122
-1
5
125
6
5
6
-1
...

result:

wrong answer 10th numbers differ - expected: '7', found: '10'