Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define GCC Optimaze("Ofast")
- #include <bits/stdc++.h>
- #define all(x) (x).begin(),(x).end()
- using namespace std;
- using ll = long long;
- const int LOG = 18;
- const int N = 100100;
- const ll mod = 65537;
- int normalize(ll x) {
- x %= mod;
- x += mod;
- x %= mod;
- return x;
- }
- int add(ll a, ll b) {
- return normalize(a + b);
- }
- int sub(ll a, ll b) {
- return normalize(a - b);
- }
- ll mult(ll a, ll b) {
- a = normalize(a);
- b = normalize(b);
- return normalize(a * b);
- }
- ll fastPow(ll a, ll p) {
- ll ans = 1;
- a = normalize(a);
- while (p) {
- if (p & 1) {
- ans *= a;
- ans %= mod;
- }
- a *= a;
- a %= mod;
- p /= 2;
- }
- return normalize(ans);
- }
- ll inv(ll a) {
- return fastPow(a, mod - 2);
- }
- namespace {
- template<int n, typename T = int>
- void mult(const T *__restrict a, const T *__restrict b, T *__restrict res) {
- if (n <= 64) {
- for (int i = 0; i < n; i++) {
- for (int j = 0; j < n; j++) {
- res[i + j] += a[i] * 1ll * b[j] % mod;
- res[i + j] = normalize(res[i + j]);
- }
- }
- } else {
- const int mid = n / 2;
- alignas(64) T btmp[n], E[n] = {};
- auto atmp = btmp + mid;
- for (int i = 0; i < mid; i++) {
- atmp[i] = (a[i] + a[i + mid]) % mod;
- btmp[i] = (b[i] + b[i + mid]) % mod;
- }
- mult<mid>(atmp, btmp, E);
- mult<mid>(a + 0, b + 0, res);
- mult<mid>(a + mid, b + mid, res + n);
- for (int i = 0; i < mid; i++) {
- const auto tmp = res[i + mid];
- res[i + mid] += E[i] - res[i] - res[i + 2 * mid];
- res[i + 2 * mid] += E[i + mid] - tmp - res[i + 3 * mid];
- res[i + mid] = normalize(res[i + mid]);
- res[i + 2 * mid] = normalize(res[i + 2 * mid]);
- }
- }
- }
- }
- static alignas(64) int A[N], B[N], ans[N], fact[N], invfact[N];
- void Solve() {
- int n, k;
- cin >> n >> k;
- k = normalize(k);
- vector<ll> b(n);
- memset(A, 0, sizeof A);
- memset(B, 0, sizeof B);
- memset(ans, 0, sizeof ans);
- for (int i = 0; i < n; i++) cin >> b[i];
- for (int i = 0; i < n; i++) {
- b[i] = normalize(b[i]);
- }
- for (int i = 0; i < n; i++) {
- B[i] = mult(b[n - 1 - i], invfact[i]);
- A[i] = mult(fastPow(normalize(-k), i), invfact[i]);
- }
- const int NMAX = 1 << LOG;
- mult<NMAX>(A, B, ans);
- for (int i = 0; i < n; i++) {
- cout << mult(ans[i], fact[i]) << " ";
- }
- cout << "\n";
- }
- int main() {
- ios_base::sync_with_stdio(false);
- cin.tie(nullptr);
- cout.tie(nullptr);
- fact[0] = 1;
- invfact[0] = 1;
- for (int i = 1; i < N; i++) {
- fact[i] = mult(fact[i - 1], i);
- invfact[i] = inv(fact[i]);
- }
- int t;
- cin >> t;
- while (t--) {
- Solve();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement