QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#588334#9376. GameyuannnWA 173ms3652kbC++231.2kb2024-09-25 09:40:552024-09-25 09:40:55

Judging History

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

  • [2024-09-25 09:40:55]
  • 评测
  • 测评结果:WA
  • 用时:173ms
  • 内存:3652kb
  • [2024-09-25 09:40:55]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'

//只需要知道这个题目涉及:辗转相除(那么不用题解,也能把这个题目给补了)
//思维很简单,主要看的是,怎么去模拟实现 在m'n


const int mod=998244353;

int fpow(int x,int n){
    int ans=1;
    while(n){
        if(n&1) ans=ans*x%mod;
        x=x*x%mod;
        n>>=1;
    }
    return ans;
}
int ans=0,now=1;
int p1,p2;
int gcd(int x,int y,int op){
    if(x==0) return 0;
    int e=(y+x-1)/x;
    if(op==1){
        if(y%x==0)ans=(ans+now*fpow(p1,e)%mod)%mod;
        now=now*p1%mod;
    }
    else ans=(ans+now*p1%mod*(fpow(p2,e)-1)%mod*fpow(p2-1,mod-2)%mod+mod)%mod,now=now*p2%mod;
    return gcd(y%x,x,op^1);
}

void solve(){
    int x,y;cin>>x>>y;
    int a0,a1,b;
    cin>>a0>>a1>>b;
    p1=a0*fpow(a0+a1,mod-2)%mod;
    p2=a1*fpow(a0+a1,mod-2)%mod;
    ans=0,now=1;
    if(x==y){cout<<p1<<endl;return;}
    if(x<y)  gcd(x,y,1);
    else  gcd(y,x,0);
    cout<<ans<<endl;
}






signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
    int t = 1;
    cin >> t;
    while (t--) solve();
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: 60ms
memory: 3652kb

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: 173ms
memory: 3640kb

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:

353981125
891989120
289747281
835703058
422716328
866876218
775993888
534370160
75162703
897762481
480143278
152438787
627273627
877763156
569459062
517670740
726871675
595927601
467756370
8742042
576876527
93098213
769577181
412145088
772773385
325934407
498676577
829244320
136118131
702271520
2867...

result:

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