QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#581899 | #9376. Game | mooninsea | ML | 0ms | 3696kb | C++17 | 719b | 2024-09-22 14:32:35 | 2024-09-22 14:32:35 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
const int N=998244353;
#define ll long long
ll quick(ll n,ll m){
ll sum=1;
while(m){
if(m&1)sum=sum*n%N;
m>>=1;
n=n*n%N;
}
return sum%N;
}
ll op=1;
ll possi(ll a,ll b,ll pa, ll pb){
if(a==b){
return pa*quick(pa+pb,N-2)%N;
}
if(a<b){
ll g=b/a;
if(g*a!=b)b-=g*a;
else {
g--;
b=a;
}
return possi(a,b,pa,pb)%N*quick(pa,g)%N*quick(quick(pa+pb,g),N-2)%N;
}else{
return (possi(a-b,b,pa,pb)%N*quick(pa+pb,N-2)*pb%N+quick(pa+pb,N-2)*pa%N)%N;
}
}
int main(){
int T;
cin>>T;
while(T--){
int a,b;
cin>>a>>b;
ll qa,qb,qc;
cin>>qa>>qb>>qc;
op=1;
cout<<possi(a,b,qa,qb);
if(T!=0)cout<<"\n";
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3696kb
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
Memory Limit Exceeded
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