結果

問題 No.1409 Simple Math in yukicoder
ユーザー SHIJOUSHIJOU
提出日時 2021-04-13 18:20:28
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 14 ms / 2,000 ms
コード長 5,651 bytes
コンパイル時間 1,853 ms
コンパイル使用メモリ 208,016 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-06-29 23:26:48
合計ジャッジ時間 24,863 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 1 ms
5,376 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 AC 1 ms
5,376 KB
testcase_04 AC 1 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 1 ms
5,376 KB
testcase_07 AC 3 ms
5,376 KB
testcase_08 AC 6 ms
5,376 KB
testcase_09 AC 3 ms
5,376 KB
testcase_10 AC 5 ms
5,376 KB
testcase_11 AC 6 ms
5,376 KB
testcase_12 AC 5 ms
5,376 KB
testcase_13 AC 3 ms
5,376 KB
testcase_14 AC 3 ms
5,376 KB
testcase_15 AC 4 ms
5,376 KB
testcase_16 AC 3 ms
5,376 KB
testcase_17 AC 7 ms
5,376 KB
testcase_18 AC 5 ms
5,376 KB
testcase_19 AC 5 ms
5,376 KB
testcase_20 AC 4 ms
5,376 KB
testcase_21 AC 4 ms
5,376 KB
testcase_22 AC 5 ms
5,376 KB
testcase_23 AC 2 ms
5,376 KB
testcase_24 AC 2 ms
5,376 KB
testcase_25 AC 5 ms
5,376 KB
testcase_26 AC 5 ms
5,376 KB
testcase_27 AC 8 ms
5,376 KB
testcase_28 AC 8 ms
5,376 KB
testcase_29 AC 8 ms
5,376 KB
testcase_30 AC 8 ms
5,376 KB
testcase_31 AC 8 ms
5,376 KB
testcase_32 AC 7 ms
5,376 KB
testcase_33 AC 8 ms
5,376 KB
testcase_34 AC 8 ms
5,376 KB
testcase_35 AC 8 ms
5,376 KB
testcase_36 AC 9 ms
5,376 KB
testcase_37 AC 12 ms
5,376 KB
testcase_38 AC 12 ms
5,376 KB
testcase_39 AC 12 ms
5,376 KB
testcase_40 AC 13 ms
5,376 KB
testcase_41 AC 12 ms
5,376 KB
testcase_42 AC 13 ms
5,376 KB
testcase_43 AC 13 ms
5,376 KB
testcase_44 AC 12 ms
5,376 KB
testcase_45 AC 13 ms
5,376 KB
testcase_46 AC 13 ms
5,376 KB
testcase_47 AC 12 ms
5,376 KB
testcase_48 AC 13 ms
5,376 KB
testcase_49 AC 12 ms
5,376 KB
testcase_50 AC 12 ms
5,376 KB
testcase_51 AC 12 ms
5,376 KB
testcase_52 AC 14 ms
5,376 KB
testcase_53 AC 12 ms
5,376 KB
testcase_54 AC 13 ms
5,376 KB
testcase_55 AC 12 ms
5,376 KB
testcase_56 AC 12 ms
5,376 KB
testcase_57 AC 12 ms
5,376 KB
testcase_58 AC 13 ms
5,376 KB
testcase_59 AC 12 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<n; ++i)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using ll = int64_t;
using ull = uint64_t;
using ld = long double;
using P = pair<int, int>;
using vs = vector<string>;
using vi = vector<int>;
using vvi = vector<vi>;
template<class T> using PQ = priority_queue<T>;
template<class T> using PQG = priority_queue<T, vector<T>, greater<T>>;
const int INF = 0xccccccc;
const ll LINF = 0xcccccccccccccccLL;
template<typename T1, typename T2>
inline bool chmax(T1 &a, T2 b) {return a < b && (a = b, true);}
template<typename T1, typename T2>
inline bool chmin(T1 &a, T2 b) {return a > b && (a = b, true);}
template<typename T1, typename T2>
istream &operator>>(istream &is, pair<T1, T2> &p) { return is >> p.first >> p.second;}
template<typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p) { return os << p.first << ' ' << p.second;}

constexpr int64_t safe_mod(int64_t x, int64_t m) {
  x %= m;
  if(x < 0) x += m;
  return x;
}

constexpr pair<int64_t, int64_t> inv_gcd(int64_t a, int64_t b) {
  a = safe_mod(a, b);
  if(a == 0) return {b, 0};
  int64_t s = b, t = a;
  int64_t m0 = 0, m1 = 1;
  while(t) {
    int64_t u = s/t;
    s -= t*u;
    m0 -= m1*u;
    int64_t tmp = s;
    s = t;
    t = tmp;
    tmp = m0;
    m0 = m1;
    m1 = tmp;
  }
  if(m0 < 0) m0 += b/s;
  return {s, m0};
}

// 最初に d_mint::set_mod(m) を行う
struct d_mint {
  struct barrett {
    unsigned int _m;
    uint64_t im;
    barrett(unsigned int m):_m(m), im(uint64_t(-1)/m + 1) {}
    unsigned int umod() const {return _m;}
    unsigned int mul(unsigned int a, unsigned int b) const {
      uint64_t z = a;
      z *= b;
      uint64_t x = uint64_t(((unsigned __int128)(z)*im) >> 64);
      unsigned int v = (unsigned int)(z-x*_m);
      if(_m <= v) v += _m;
      return v;
    }
  };

  unsigned int x;
  static barrett bt;
  static unsigned int umod() {return bt.umod();}
  static int mod() {return int(bt.umod());}
  static void set_mod(int m) {
    assert(1 <= m);
    bt = barrett(m);
  }
  static d_mint raw(int v) {
    d_mint z;
    z.x = v;
    return z;
  }

  d_mint() : x(0) {}
  template<class T>
  d_mint(T v) {
    int64_t z = int64_t(v % int64_t(mod()));
    if(z < 0) z += mod();
    x = (unsigned int)(z);
  }

  d_mint& operator++() {
    x++;
    if(x == umod()) x = 0;
    return *this;
  }
  d_mint& operator--() {
    if(x == 0) x = umod();
    x--;
    return *this;
  }
  d_mint operator++(int) {
    d_mint result = *this;
    ++*this;
    return result;
  }
  d_mint operator--(int) {
    d_mint result = *this;
    --*this;
    return result;
  }

  d_mint& operator+=(const d_mint &rhs) {
    x += rhs.x;
    if(x >= umod()) x -= umod();
    return *this;
  }
  d_mint& operator-=(const d_mint &rhs) {
    x += mod() - rhs.x;
    if(x >= umod()) x -= umod();
    return *this;
  }
  d_mint& operator*=(const d_mint &rhs) {
    x = bt.mul(x, rhs.x);
    return *this;
  }
  d_mint& operator/=(const d_mint& rhs) {
    return *this = *this * rhs.inv();
  }

  d_mint operator+() const {return *this;}
  d_mint operator-() const {return d_mint() - *this;}

  d_mint pow(int64_t n) const {
    assert(0 <= n);
    d_mint z = *this, r = 1;
    while(n) {
      if(n&1) r *= z;
      z *= z;
      n >>= 1;
    }
    return r;
  }
  d_mint inv() const {
    auto eg = inv_gcd(x, mod());
    assert(eg.first == 1);
    return eg.second;
  }
  friend d_mint operator+(const d_mint &lhs, const d_mint &rhs) {
    return d_mint(lhs) += rhs;
  }
  friend d_mint operator-(const d_mint &lhs, const d_mint &rhs) {
    return d_mint(lhs) -= rhs;
  }
  friend d_mint operator*(const d_mint &lhs, const d_mint &rhs) {
    return d_mint(lhs) *= rhs;
  }
  friend d_mint operator/(const d_mint &lhs, const d_mint &rhs) {
    return d_mint(lhs) /= rhs;
  }
  friend bool operator==(const d_mint &lhs, const d_mint &rhs) {
    return lhs.x == rhs.x;
  }
  friend bool operator!=(const d_mint &lhs, const d_mint &rhs) {
    return lhs.x != rhs.x;
  }
  friend istream &operator>>(istream &is, d_mint &x) {return is >> x.x;}
  friend ostream &operator<<(ostream &os, const d_mint &x) {return os << x.x;}
};
d_mint::barrett d_mint::bt = 998244353;


constexpr int64_t pow_mod_constexpr(int64_t x, int64_t n, int m) {
  if(m == 1) return 0;
  unsigned int _m = (unsigned int)(m);
  uint64_t r = 1;
  uint64_t y = safe_mod(x, m);
  while(n) {
    if(n&1) r = (r*y)%_m;
    y = (y*y)%_m;
    n >>= 1;
  }
  return r;
}

constexpr int primitive_root_constexpr(int m) {
  if(m == 2) return 1;
  if(m == 167772161) return 3;
  if(m == 469762049) return 3;
  if(m == 754974721) return 11;
  if(m == 998244353) return 3;
  int divs[20] = {};
  divs[0] = 2;
  int cnt = 1;
  int x = (m-1)>>1;
  while(~x&1) x >>= 1;
  for(int i = 3; (int64_t)(i)*i <= x; i += 2) {
    if(x%i == 0) {
      divs[cnt++] = i;
      while(x%i == 0) x /= i;
    }
  }
  if(x > 1) divs[cnt++] = x;
  for(int g = 2;; g++) {
    bool ok = true;
    for(int i = 0; i < cnt; i++) {
      if(pow_mod_constexpr(g, (m-1)/divs[i], m) == 1) {
        ok = false;
        break;
      }
    }
    if(ok) return g;
  }
}

//head



int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int t;
  cin >> t;
  while(t--) {
    int v, x;
    cin >> v >> x;
    int mod = v*x+1;
    d_mint::set_mod(mod);
    d_mint g = primitive_root_constexpr(mod);
    g = g.pow(v);
    d_mint now(1);
    vi ans(x);
    rep(i, x) {
      now *= g;
      ans[i] = now.x;
    }
    sort(all(ans));
    rep(i, x) cout << ans[i] << (i == x-1?'\n':' ');
  }
}
0