QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#584825 | #9376. Game | yywxdgy | RE | 51ms | 3944kb | C++14 | 1.3kb | 2024-09-23 16:57:47 | 2024-09-23 16:57:47 |
Judging History
answer
#include <iostream>
#include <cstdio>
#include <string.h>
const int mod = 998244353;
using namespace std;
#define gc() getchar()
inline int read() {
char c = gc(); int s = 0;
for (; !isdigit(c); c = gc());
for (; isdigit(c); c = gc()) s = s * 10 + c - 48;
return s;
}
inline int mul(int a, int b) { return 1ll*a*b%mod; }
inline int add(int a, int b) { return a + b >= mod ? a + b - mod : a + b; }
inline int dec(int a, int b) { return a-b<0?a-b+mod:a-b; }
int Power(int a, int b) {
int ans = 1;
for (; b; b >>= 1) (b & 1 ? ans = mul(ans, a) : 0), a = mul(a, a);
return ans;
}
int a1, a2, b, P, Q;
int X, Y;
int fun(int x, int y) {
if (x == y) return P;
if (x == 1) return Power(P, y);
if (x < y) return mul(Power(P, (y - 1) / x), fun(x, y - (y - 1) / x * x));
int a = x / y, sum = 0;
sum = dec(1, Power(Q, a));
if (y == 1) return sum;
return mul(sum, mul(Power(Q, a), fun(x - x / y * y, y)));
}
void Work() {
X = read(), Y = read();
a1 = read(), a2 = read(), b = read();
P = mul(a1, Power(add(a1,a2), mod - 2));
Q = mul(a2, Power(add(a1,a2), mod - 2));
printf("%d\n", fun(X, Y));
}
int main() {
int T; cin >> T;
while (T --) Work();
return 0;
}
/*
3
1 1
2 2 6
1 3
2 3 6
3 4
7 3 15
*/
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3880kb
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: 51ms
memory: 3944kb
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
Runtime Error
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...