結果

問題 No.1409 Simple Math in yukicoder
ユーザー SHIJOUSHIJOU
提出日時 2021-04-13 18:04:53
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 4,633 bytes
コンパイル時間 1,954 ms
コンパイル使用メモリ 202,692 KB
実行使用メモリ 10,624 KB
最終ジャッジ日時 2024-06-29 23:05:05
合計ジャッジ時間 30,617 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
10,624 KB
testcase_01 AC 2 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 2 ms
5,376 KB
testcase_07 AC 171 ms
5,376 KB
testcase_08 AC 593 ms
5,376 KB
testcase_09 AC 148 ms
5,376 KB
testcase_10 AC 468 ms
5,376 KB
testcase_11 AC 577 ms
5,376 KB
testcase_12 AC 447 ms
5,376 KB
testcase_13 AC 169 ms
5,376 KB
testcase_14 AC 133 ms
5,376 KB
testcase_15 AC 201 ms
5,376 KB
testcase_16 AC 217 ms
5,376 KB
testcase_17 AC 757 ms
5,376 KB
testcase_18 AC 372 ms
5,376 KB
testcase_19 AC 392 ms
5,376 KB
testcase_20 AC 321 ms
5,376 KB
testcase_21 AC 258 ms
5,376 KB
testcase_22 AC 479 ms
5,376 KB
testcase_23 AC 104 ms
5,376 KB
testcase_24 AC 82 ms
5,376 KB
testcase_25 AC 468 ms
5,376 KB
testcase_26 AC 511 ms
5,376 KB
testcase_27 AC 863 ms
5,376 KB
testcase_28 AC 810 ms
5,376 KB
testcase_29 AC 848 ms
5,376 KB
testcase_30 AC 846 ms
5,376 KB
testcase_31 AC 883 ms
5,376 KB
testcase_32 AC 793 ms
5,376 KB
testcase_33 AC 842 ms
5,376 KB
testcase_34 AC 809 ms
5,376 KB
testcase_35 AC 849 ms
5,376 KB
testcase_36 AC 896 ms
5,376 KB
testcase_37 TLE -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
testcase_42 -- -
testcase_43 -- -
testcase_44 -- -
testcase_45 -- -
testcase_46 -- -
testcase_47 -- -
testcase_48 -- -
testcase_49 -- -
testcase_50 -- -
testcase_51 -- -
testcase_52 -- -
testcase_53 -- -
testcase_54 -- -
testcase_55 -- -
testcase_56 -- -
testcase_57 -- -
testcase_58 -- -
testcase_59 -- -
権限があれば一括ダウンロードができます

ソースコード

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;

//head



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