QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#621858#9376. GameSakuyamaidWA 966ms3704kbC++201.9kb2024-10-08 17:38:332024-10-08 17:38:33

Judging History

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

  • [2024-10-08 17:38:33]
  • 评测
  • 测评结果:WA
  • 用时:966ms
  • 内存:3704kb
  • [2024-10-08 17:38:33]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define int long long
using LL = long long;
constexpr int mod = 998244353;

int ksm(int a, int b){
    a %= mod;
    int res = 1;
    while(b){
        if(b & 1)res = res * a % mod;
        a = a * a % mod;
        b >>= 1;
    }
    return res;
}

int n, k;
int x, y, a0, a1, b, c;
int num;
int ans1, ans2, inv, ans;

int get(int x){
    return x * inv % mod;
}

int dfs(int now1, int now2){
    if(now1 == now2){
        return get(a0);
    }else if(now1 < now2){
        int num = ((now2 - 1) / now1);
        if(now1 == now2 - num * now1){
            int cnt = ksm(get(a0), num + 1);
            return cnt;
        }else {
            int now = now2 - num * now1;
            return ksm(get(a0), num) * dfs(now1, now) % mod;
        }
    }else {
        int num = ((now1 - 1) / now2);
        if(now2 == now1 - num * now2){
            int cnt = ksm(inv, num + 1);
            int cc1 = ksm(c, num + 1);
            int cc2 = ksm(a1, num + 1);
            return cnt * (((cc1 - cc2) % mod + mod) % mod) % mod;
        }else {
            int now = now1 - num * now2;
            int cnt = ksm(inv, num);
            int cc1 = ksm(c, num);
            int cc2 = ksm(a1, num);
            return cnt * (((cc1 - cc2) % mod + mod) % mod) % mod * dfs(now, now2) % mod;
        }
    }
}

void Sakuya(){
    cin >> x >> y;
    cin >> a0 >> a1 >> b;
    inv = 1;
    c = a0 + a1;
    for(int i = 2; i <= sqrt(c); ++ i){
        while(c % i == 0){
            inv *= ksm(i, mod - 2);
            inv %= mod;
            c /= i;
        }
    }
    if(c){
        inv *= ksm(c, mod - 2);
        inv %= mod;
    }
    c = a1 + a0;
    cout << dfs(x, y) << "\n"; 
}

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int T;
    for(cin >> T; T --; )
        Sakuya();
}

详细

Test #1:

score: 100
Accepted
time: 1ms
memory: 3604kb

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: 0
Accepted
time: 935ms
memory: 3668kb

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:

947058399
376449942
612621163
138416357
592200562
45779380
870227707
169499045
86396463
415694940
46851356
951368934
426243016
864656779
750317399
922456360
486881524
824329239
198191519
189360084
966510181
512645443
695650039
703100783
550002158
438470182
246877045
39876086
667870434
405196653
5935...

result:

ok 100000 lines

Test #3:

score: -100
Wrong Answer
time: 966ms
memory: 3704kb

input:

100000
167959139 481199252
18199423 25950409 149762920
773386884 579721198
16629525 28339910 152155823
2087506 268792718
43528658 6471925 90197530
691952768 717268783
516613092 94328992 743662288
45277106 856168102
309821265 346013425 963168258
279198849 527268921
30167950 166388455 577970339
140515...

output:

608995310
620079102
727965251
354043457
237529370
185705341
688746363
797524782
194679713
97357232
289151763
196821352
493643448
202200956
308868970
865672284
926620746
789172633
354204967
857714362
339201365
657279957
147359153
320705968
942666612
366758550
130408608
278851852
211011173
863472585
4...

result:

wrong answer 1st lines differ - expected: '623291477', found: '608995310'