QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#581909#9376. Gamechenzq7WA 62ms3644kbC++141.5kb2024-09-22 14:33:552024-09-22 14:33:59

Judging History

你现在查看的是最新测评结果

  • [2024-09-22 14:33:59]
  • 评测
  • 测评结果:WA
  • 用时:62ms
  • 内存:3644kb
  • [2024-09-22 14:33:55]
  • 提交

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+(quickpow(p1,n)*e.first)%mod)%mod,(quickpow(b,n)*e.second)%mod};
	}
}
void solve()
{
	int x,y;
    cin >> x >> y >> p0 >> p1 >> b;
    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: 3556kb

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: 62ms
memory: 3644kb

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
-911847890
415694940
46851356
951368934
426243016
864656779
750317399
922456360
486881524
824329239
198191519
189360084
966510181
512645443
695650039
-295143570
550002158
-559774171
246877045
39876086
667870434
405196653
...

result:

wrong answer 9th lines differ - expected: '86396463', found: '-911847890'