QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#591722#9376. GamelamkappaWA 49ms3660kbC++201.2kb2024-09-26 17:24:102024-09-26 17:24:10

Judging History

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

  • [2024-09-26 17:24:10]
  • 评测
  • 测评结果:WA
  • 用时:49ms
  • 内存:3660kb
  • [2024-09-26 17:24:10]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
using i64 = long long;

constexpr i64 M = 998244353;

i64 qpow(i64 x, i64 y=M-2){
    x %= M; y %= M;
    i64 res = 1;
    while(y){
        if(y & 1) res = res*x%M;
        x = x*x%M;
        y >>= 1;
    }
    return res;
}

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

    int T = 1;
    cin >> T;
    while(T--){
        i64 x, y; cin >> x >> y;
        i64 a0, a1, b; cin >> a0 >> a1 >> b;
        i64 p0 = a0 * qpow(a0+a1) % M;
        i64 p1 = a1 * qpow(a0+a1) % M;

        auto T = make_pair(x, y);
        i64 px = 0, pl = 1;
        do{
            if(x > y){
                auto k = (x - 1) / y;
                x -= k * y;
                // y *= 2;
                px = (px + pl * p0 % M * (qpow(p1, k) + M - 1) % M * qpow(p1 + M - 1) % M) % M;
                pl = pl * qpow(p1, k) % M;
            }else if(x < y){
                auto k = (y - 1) / x;
                y -= k * x;
                // x *= 2;
                pl = pl * qpow(p0, k) % M;
            }else{
                px = (px + pl * p0 % M) % M;
                break;
            }
        }while(1);

        cout << px << '\n';
    }

    return 0;
}


Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

3
1 1
2 2 6
1 3
2 3 6
3 4
7 3 15

output:

499122177
910398850
220911476

result:

ok 3 lines

Test #2:

score: -100
Wrong Answer
time: 49ms
memory: 3660kb

input:

100000
1 1000000000
12980050 128257807 266126484
1 1000000000
400255084 123438563 768881284
1000000000 1000000000
24563487 72082135 450057094
1 1000000000
56952077 40876000 193815114
1000000000 1000000000
82048274 239365585 326520865
1000000000 1
309821265 346013425 963168258
1 1
104158269 199365020...

output:

748335608
323192958
612621163
528044714
592200562
749406445
870227707
169499045
775687297
415694940
835839043
471022311
426243016
864656779
750317399
857785388
486881524
783895931
198191519
189360084
966510181
512645443
695650039
161287374
550002158
689854153
6944159
28324312
667870434
725872296
593...

result:

wrong answer 1st lines differ - expected: '947058399', found: '748335608'