QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#585034 | #9376. Game | nbptZJH | WA | 95ms | 3708kb | C++20 | 1.2kb | 2024-09-23 18:32:38 | 2024-09-23 18:32:39 |
Judging History
answer
#include<bits/stdc++.h>
#define int long long
#define pii pair<int,int>
#define endl '\n'
using namespace std;
const int N=1e6+10;
const int mod=998244353;
int qpow(int a,int n){
int ans=1;
while(n){
if(n&1)ans=ans*a%mod;
a=a*a%mod;
n/=2;
}
return ans;
}
int a,b,c;
int cnt;
int pa,pb;
void dfs(int l,int r,int p){
if(r>l){
int cs=(r-1)/l;
int rs=p*qpow(pa,cs)%mod;
// cout<<cs<<" "<<cnt<<endl;
dfs(l,r-cs*l,rs);
}
else if(r==l){
cnt=(cnt+p*pa%mod)%mod;
// cout<<"fin"<<" "<<cnt<<endl;
}
else{
int cs=(l-1)/r;
int fz=(qpow(a+b,cs)-qpow(b,cs)+mod)%mod*qpow(qpow(a+b,cs),mod-2)%mod;
int fm=a%mod*qpow(a+b,mod-2)%mod;
int rs=pa*p%mod*fz%mod*qpow(fm,mod-2)%mod;
cnt+=rs;
cnt%=mod;
rs=p*qpow(pb,cs)%mod;
// cout<<cs<<" "<<cnt<<endl;
if(l-cs*r<r)return;
dfs(l-cs*r,r,rs);
}
}
void solve(){
int x,y;
cin>>x>>y;
cin>>a>>b>>c;
cnt=0;
pa=a*qpow(a+b,mod-2)%mod;
pb=b*qpow(a+b,mod-2)%mod;
dfs(x,y,1);
// cout<<pa*pa%mod*pa%mod<<endl;
cout<<cnt<<endl;
}
signed main(){
ios::sync_with_stdio(false);
cin.tie(0);cout.tie(0);
int T=1;
cin>>T;
while(T--){
solve();
}
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3688kb
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: 80ms
memory: 3708kb
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: 95ms
memory: 3636kb
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:
856446590 245280510 139485110 231907167 417323648 436205957 835928709 622001469 766432647 682707650 841011161 787273264 679387554 678340777 923316750 359292771 147637794 959207844 526967336 934093433 523854806 313916280 20843134 724894048 753002617 458373710 368934853 997326947 124013408 249283340 5...
result:
wrong answer 1st lines differ - expected: '623291477', found: '856446590'