QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#584535 | #9376. Game | Yu_mx | WA | 99ms | 3692kb | C++14 | 1.4kb | 2024-09-23 15:06:17 | 2024-09-23 15:06:17 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ios ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define endl '\n'
const int MOD = 998244353;
ll qmi(ll a,ll k,ll p){
ll res = 1%p;
while(k){
if(k&1) res = 1LL*res*a%p;
k >>= 1;
a = 1LL*a*a%p;
}
return res;
}
ll lcm(ll xx,ll yy){
return yy/__gcd(xx,yy)%MOD*xx%MOD;
}
void solve(){
ll x,y,px,py,b,ansfz=0,ansfm=1;
ll fz0 = 1,fm0 = 1;
cin>>x>>y;
cin>>px>>py>>b;
b = px+py;
while(y){
ll fz, fm;
ll fz1 = fz0, fm1 = fm0;
ll n;
if(x>y){
n = (x-1)/y;
x -= n*y;
fz0 = fz0*qmi(py,n,MOD)%MOD;
fm0 = fm0*qmi(b,n,MOD)%MOD;
fz = (px*qmi(b,n,MOD)%MOD+MOD-px*qmi(py,n,MOD)%MOD)%MOD;
fm = (qmi(b,n+1,MOD)+MOD-py*qmi(b,n,MOD)%MOD)%MOD;
}
else{
n = y/x;
y -= n*x;
fz0 = fz0*qmi(px,n,MOD)%MOD;
fm0 = fm0*qmi(b,n,MOD)%MOD;
if(y!=0) fz = 0;
else{
fz = qmi(px,n,MOD)%MOD;
fm = qmi(b,n,MOD)%MOD;
}
}
ll tt = __gcd(fz,fm);
fz /= tt;
fm /= tt;
fz = fz*fz1%MOD;
fm = fm*fm1%MOD;
tt = lcm(ansfm,fm);
//cout<<x<<' '<<y<<' '<<fz<<' '<<fm<<endl;
ansfz = (tt/ansfm*ansfz%MOD+tt/fm*fz%MOD)%MOD;
ansfm = tt%MOD;
tt =__gcd(fz0,fm0);
fz0 /= tt;
fm0 /= tt;
}
ll ans;
ans = ansfz%MOD*qmi(ansfm,MOD-2,MOD)%MOD;
//cout<<ansfz<<' '<<ansfm<<endl;
cout<<ans<<endl;
}
int main(){
ios;
ll T;cin>>T;while(T--)
solve();
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3692kb
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: 99ms
memory: 3584kb
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 0 870227707 169499045 878937776 415694940 185158637 951368934 426243016 864656779 750317399 864285484 486881524 824329239 198191519 189360084 966510181 512645443 695650039 54160743 550002158 819139866 246877045 39876086 667870434 405196653 593590760 ...
result:
wrong answer 6th lines differ - expected: '45779380', found: '0'