QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#583472 | #9376. Game | huangce | ML | 0ms | 3708kb | C++17 | 1.1kb | 2024-09-22 20:06:39 | 2024-09-22 20:06:39 |
Judging History
answer
/*
* @Author: dsaDadas11
* @Date: 2024-06-27 10:33:26
* @LastEditTime: 2024-09-22 20:05:06
* @Description: go for it!
*/
#include<bits/stdc++.h>
#define endl '\n'
#define ll long long
#define int ll
using namespace std;
constexpr int N=1e6+7;
constexpr int M=2e3+7;
constexpr int mod=998244353;
int quickpow(int x,int y)
{
int ans=1;
while(y)
{
if(y&1) ans=(ans*x)%mod;
x=(x*x)%mod;
y>>=1;
}
return ans;
}
int niyuan(int x)
{
return quickpow(x,mod-2);
}
int x,y;
int a0,a1,b,a;
int p0,p1;
int dfs(int x,int y)
{
if(x>y)
{
return (p1*dfs(x-y,y)%mod+p0)%mod;
}
if(x==y)
{
return p0;
}
return 0;
}
void solve()
{
cin>>x>>y;
cin>>a0>>a1>>b;
a=a0+a1;
p0=a0*niyuan(a)%mod;
p1=a1*niyuan(a)%mod;
if(x==y)
{
cout<<p0<<endl;
return;
}
int tp=1;
if(x<y)
{
int cnt=y/x;
tp=quickpow(p0,cnt);
y-=cnt*x;
if(y==0)
{
cout<<tp<<endl;
return;
}
}
// 现在 x>y了
int ans=tp*dfs(x,y)%mod;
cout<<ans<<endl;
}
signed main()
{
ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
int T=1; cin>>T;
while(T--){solve();}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3708kb
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...