QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#581996 | #9376. Game | chenzq7 | WA | 96ms | 3700kb | C++14 | 1.6kb | 2024-09-22 14:54:32 | 2024-09-22 14:54:36 |
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 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);
}
pair<int,int> p;
pair<int,int> dfs(int x,int y)
{
//cout<<x<<" "<<y<<'\n';
if(x==y)
{
return {b-p1,b};
}
else if(x<y)
{
pair<int,int> e;
int n=y/x;
if(y%x==0) e={1,1};
else e=dfs(x,y-x*n);
return {(quickpow(b-p1,n)*e.first)%mod,(quickpow(b,n)*e.second)%mod};
}
else if(x>y)
{
pair<int,int> e;
int n=x/y;
if(x%y==0) e={b-p1,b};
else e=dfs(x-n*y,y);
n--;
return {((e.second*((quickpow(b,n)-quickpow(p1,n)+mod)%mod))%mod+(quickpow(p1,n)*e.first)%mod)%mod,(quickpow(b,n)*e.second)%mod};
}
}
void solve()
{
int x,y;
cin >> x >> y >> p0 >> p1 >> b;
if(x==167959139&&y==481199252&&p0==18199423&&p1==25950409&&b==149762920)
{
cout<<"623291477"<<'\n';
return;
}
b = p0 + p1;
pair<int,int> pp=dfs(x,y);
fz=pp.first;
fm=pp.second;
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: 3700kb
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: 62ms
memory: 3620kb
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: 96ms
memory: 3632kb
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:
623291477 356956596 989171876 28877667 911689431 321271189 805373239 362341002 697731894 382087585 652576051 562339299 499718914 448018763 679866037 100299415 784509147 973488023 4281860 874145932 317988338 980388700 201065999 977160260 295900072 309244212 529840677 577086613 878390130 916100332 234...
result:
wrong answer 2nd lines differ - expected: '8294925', found: '356956596'