QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#179066 | #6887. Data Generation | PPP# | AC ✓ | 130ms | 3580kb | C++17 | 1.3kb | 2023-09-14 17:25:49 | 2023-09-14 17:25:49 |
Judging History
answer
#ifdef DEBUG
#define _GLIBCXX_DEBUG
#endif
//#pragma GCC optimize("O3")
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const ll mod = 998244353;
ll mult(ll a, ll b) {
return (1LL * (a % mod) * (b % mod)) % mod;
}
ll sub(ll a, ll b) {
ll s = (a - b) % mod;
if (s < 0) s += mod;
return s;
}
ll sum(ll a, ll b) {
ll s = (a + b) % mod;
if (s < 0) s += mod;
return s;
}
ll pw(ll a, ll b) {
if (b == 0) return 1;
if (b & 1) return mult(a, pw(a, b - 1));
ll res = pw(a, b / 2);
return mult(res, res);
}
void solve() {
ll n, m;
cin >> n >> m;
ll alpha = sub(mult(n, n), mult(n, 2));
ll div_n = pw(n, mod - 2);
alpha = mult(alpha, mult(div_n, div_n));
ll beta = mult(2, mult(div_n, div_n));
assert(alpha != 1);
ll D = mult(beta, pw(sub(1, alpha), mod - 2));
ll ini = sub(1, D);
ini = mult(ini, pw(alpha, m));
ini = sum(ini, D);
ini = sub(1, ini);
cout << mult(n, ini) << '\n';
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
#ifdef DEBUG
freopen("input.txt", "r", stdin);
#endif
int tst;
cin >> tst;
while (tst--) {
solve();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 130ms
memory: 3580kb
input:
100000 19491001 19491001 999999999449325353 939501148 400027352 999999998707619026 999999998353720210 999999999303057191 1879045722 1874448608 999999998385974740 1710466660 109045962 999999998020190078 999999998217418921 999999998898659805 999999999999986692 999999998389218199 351693073 2130408866 1...
output:
79256423 60176292 660407710 893892599 601021657 353145264 33871948 852325473 308290667 313185571 805837881 700368815 711096361 895992243 830757079 419158396 754661682 184055154 728055491 1 323104191 72240859 553717086 361196534 971355231 232530344 149284730 833553979 48731930 0 296123988 928795526 5...
result:
ok 100000 lines