QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#581238 | #9376. Game | jjjjjxs | WA | 66ms | 3660kb | C++14 | 1.4kb | 2024-09-22 11:03:11 | 2024-09-22 11:03:15 |
Judging History
answer
#include <bits/stdc++.h>
#define int long long
#define INF 0x3f3f3f3f
#define fr first
#define se second
#define endl '\n'
using namespace std;
typedef long long ll;
typedef pair<int,int> PII;
const int N = 2e5 + 10;
const int MOD = 998244353;
ll qpow(int a, int b, int p)
{
ll res = 1;
while (b)
{
if (b & 1) res = res * a % p;
b >>= 1;
a = 1ll * a * a % p;
}
return res;
}
int x,y;
int a0,a1,b;
void solve()
{
cin>>x>>y;
cin>>a0>>a1>>b;
int p = a0 * qpow( a0 + a1 , MOD - 2 , MOD) % MOD;
if(x == y)
{
cout << p << endl;
return;
}
//辗转相减x,y
ll ans = 0;
ll now = 1;//进行到当前过程时的概率
bool flag = (x<y);
while(1)
{
if(x==y)
{
if(flag) ans = (ans + now * p) % MOD;
break;
}
else if(x>y)
{
int num = (x - 1) / y;
x = x - num * y;
assert(x<=y);
ans = ( ans + now * (1 - qpow( 1 - p + MOD , num + 1 , MOD) + MOD) % MOD ) % MOD;
now = now * qpow( 1 - p + MOD , num , MOD ) % MOD;
flag = false;
}
else if(x<y)
{
int num = (y - 1) / x;
y = y - num * x;
assert(y<=x);
now = now * qpow( p , num , MOD ) % MOD;
flag = true;
//ans = (ans + now * p) % MOD;
}
}
cout << ans << endl;
}
signed main()
{
ios::sync_with_stdio(0);
cin.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: 3564kb
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: 49ms
memory: 3660kb
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: 66ms
memory: 3624kb
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:
111307212 952164090 776159793 686215457 349269124 374842963 412084092 79533762 286086009 778147923 155440529 688610964 882386961 953649977 109612740 382211901 900328335 520308570 714433628 161607199 973307502 992272281 796334630 734390111 743921125 574889610 805293646 336501070 475912248 45683411 59...
result:
wrong answer 1st lines differ - expected: '623291477', found: '111307212'