QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#585114 | #9376. Game | mt666 | WA | 128ms | 3588kb | C++17 | 1.4kb | 2024-09-23 19:02:54 | 2024-09-23 19:02:54 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define INF 2e18
#define int long long
const int N=1e6+10,mod=998244353;
int x,y,p0,p1,t;
struct Sg{
int a,b;
};
int qmi(int a,int b)
{
int res=1;
while(b)
{
if(b&1) res=res*a%mod;
a=a*a%mod;
b>>=1;
}
return res%mod;
}
int gcd(int a,int b)
{
if(!b) return a;
return gcd(b,a%b);
}
Sg dfs(int a,int b)
{
Sg res;
if(a==b)
{
res={p0,t};
return res;
}
int k=(a-1)/b;
int cnt1=p0*(qmi(t,k)-qmi(p1,k))%mod;
int cnt2=qmi(t,k)*(t-p1)%mod;
int g=gcd(cnt1,cnt2);
cnt1/=g,cnt2/=g;
res={cnt1,cnt2};
int t1=qmi(p1,(a-1)/b),t2=qmi(t,(a-1)/b);
a-=(a-1)/b*b;
int t3=qmi(p0,(b-1)/b),t4=qmi(t,(b-1)/a);
b-=(b-1)/a*a;
t1=t1*t3%mod,t2=t2*t4%mod;
g=gcd(t1,t2);
t1/=g,t2/=g;
int a1=dfs(a,b).a,b1=dfs(a,b).b;
t1=t1*a1%mod,t2=t2*b1%mod;
g=gcd(t1,t2);
t1/=g,t2/=g;
res={(t2*cnt1+t1*cnt2)%mod,cnt2*t2%mod};
g=gcd(res.a,res.b);
res.a/=g,res.b/=g;
return res;
}
void solve()
{
cin>>x>>y>>p0>>p1>>t;
t=p0+p1;
Sg ans={qmi(p0,(y-1)/x),qmi(t,(y-1)/x)};
y-=(y-1)/x*x;
ans.a=ans.a*dfs(x,y).a%mod;
ans.b=ans.b*dfs(x,y).b%mod;
int g=gcd(ans.a,ans.b);
ans.a/=g,ans.b/=g;
cout<<ans.a*qmi(ans.b,mod-2)%mod<<endl;
}
signed main()
{
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int _;
cin>>_;
while(_--) solve();
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3576kb
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
Wrong Answer
time: 128ms
memory: 3588kb
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 -295143570 550002158 -559774171 246877045 39876086 667870434 405196653 59...
result:
wrong answer 24th lines differ - expected: '703100783', found: '-295143570'