QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#581604 | #9376. Game | chenzq7 | WA | 60ms | 3700kb | C++14 | 3.3kb | 2024-09-22 13:33:46 | 2024-09-22 13:33:47 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define int ll
#define ll long long
#define buff ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define endl '\n'
const int mod = 998244353;
const int P = 998244353;
const int N = 2e5 + 7;
const int M = 1e3 + 7;
int x, y;
int p0, p1, b;
int fz,fm;
int gcd(int a,int b) {
return b>0 ? gcd(b,a%b):a;
}
int quickpow(int x, int y)
{
int ans = 1;
while (y)
{
if (y & 1)
{
ans = (ans * x) % mod;
}
y >>= 1;
x = (x * x) % mod;
}
return ans;
}
int niyuan(int x)
{
return quickpow(x, mod - 2);
}
void x_y()//x<y
{
//cout<<"<"<<'\n';
int cnt = (y / x);
y = y - x * cnt;
fz = (fz * quickpow(p0, cnt))%mod;
fm = (fm * quickpow(b, cnt))%mod;
int temp=gcd(fz,fm);
fz = fz / temp;
fm = fm / temp;
}
void x__y()//x==y
{
//cout<<"="<<'\n';
y-=x;
fz = (fz * p0) % mod;
fm = (fm * b) % mod;
int temp=gcd(fz,fm);
fz = fz / temp;
fm = fm / temp;
}
void x___y()//x>y
{
//cout<<">"<<'\n';
int cnt = (x / y);
x-=y*cnt;
y-=x;
int fenzi = ((b - p1) * (quickpow(b, cnt) - quickpow(p1, cnt))) % mod;
int fenmu = ((b - p1) * quickpow(b, cnt)) % mod;
//cout << fenzi << " " << fenmu << '\n';
fz = (fz * fenzi )% mod;
fm = (fm * fenmu )% mod;
int temp=gcd(fz,fm);
fz = fz / temp;
fm = fm / temp;
}
//int gcd(int a,int b) {
// return b>0 ? gcd(b,a%b):a;
//}
//int quickpow(int x, int y)
//{
// int ans = 1;
// while (y)
// {
// if (y & 1)
// {
// ans = (ans * x) % mod;
// }
// y >>= 1;
// x = (x * x) % mod;
// }
// return ans;
//}
//
//int niyuan(int x)
//{
// return quickpow(x, mod - 2);
//}
void solve()
{
cin >> x >> y >> p0 >> p1 >> b;
if(p0==0)
{
cout<<0<<'\n';
return;
}
if(p1==0)
{
cout<<1<<'\n';
return ;
}
b = p0 + p1;
fz = 1, fm = 1;
while(x>0&&y>0)
{
//cout<<x<<" "<<y<<'\n';
if(x<y) x_y();
else if(x==y) x__y();
else if(x>y) x___y();
}
// if (x < y)
// {
// int cnt = (y / x);
// y = y - x * cnt;
// fz = (fz * quickpow(p0, cnt))%mod;
// fm = (fm * quickpow(b, cnt))%mod;
// int temp=gcd(fz,fm);
// fz = fz / temp;
// fm = fm / temp;
// //cout << fz << " " << fm << '\n';
// }
// if (x == y)
// {
// fz = (fz * p0) % mod;
// fm = (fm * b) % mod;
// int temp=gcd(fz,fm);
// fz = fz / temp;
// fm = fm / temp;
// }
// if (x > y && y > 0)
// {
//
// int cnt = (x / y);
// int fenzi = ((b - p1) * (quickpow(b, cnt) - quickpow(p1, cnt))) % mod;
// int fenmu = ((b - p1) * quickpow(b, cnt)) % mod;
// //cout << fenzi << " " << fenmu << '\n';
// fz = (fz * fenzi )% mod;
// fm = (fm * fenmu )% mod;
// int temp=gcd(fz,fm);
// fz = fz / temp;
// fm = fm / temp;
// }
//cout << 1 << '\n';
cout << fz * niyuan(fm) % mod << endl;
}
signed main()
{
buff;
int tt = 1;
cin >> tt;
while (tt--)
{
solve();
}
return 0;
}
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
Wrong Answer
time: 60ms
memory: 3700kb
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 0 415694940 -1 951368934 426243016 864656779 750317399 922456360 486881524 824329239 198191519 189360084 966510181 512645443 695650039 0 550002158 438470182 246877045 39876086 667870434 405196653 593590760 757269629 94728...
result:
wrong answer 9th lines differ - expected: '86396463', found: '0'