結果

問題 No.2406 Difference of Coordinate Squared
ユーザー shotoyooshotoyoo
提出日時 2023-08-04 21:45:00
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 53 ms / 2,000 ms
コード長 6,924 bytes
コンパイル時間 3,071 ms
コンパイル使用メモリ 256,348 KB
実行使用メモリ 22,760 KB
最終ジャッジ日時 2024-05-05 01:36:37
合計ジャッジ時間 4,890 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 52 ms
22,656 KB
testcase_02 AC 53 ms
22,724 KB
testcase_03 AC 40 ms
22,760 KB
testcase_04 AC 49 ms
22,608 KB
testcase_05 AC 10 ms
5,376 KB
testcase_06 AC 21 ms
12,032 KB
testcase_07 AC 19 ms
10,368 KB
testcase_08 AC 9 ms
8,436 KB
testcase_09 AC 32 ms
16,816 KB
testcase_10 AC 41 ms
21,376 KB
testcase_11 AC 42 ms
18,292 KB
testcase_12 AC 15 ms
9,904 KB
testcase_13 AC 37 ms
19,128 KB
testcase_14 AC 41 ms
20,340 KB
testcase_15 AC 45 ms
22,100 KB
testcase_16 AC 28 ms
14,848 KB
testcase_17 AC 1 ms
5,376 KB
testcase_18 AC 7 ms
5,760 KB
testcase_19 AC 43 ms
20,352 KB
testcase_20 AC 39 ms
21,540 KB
testcase_21 AC 27 ms
13,660 KB
testcase_22 AC 14 ms
9,344 KB
testcase_23 AC 44 ms
22,364 KB
testcase_24 AC 11 ms
7,808 KB
testcase_25 AC 3 ms
5,376 KB
testcase_26 AC 1 ms
5,376 KB
testcase_27 AC 2 ms
5,376 KB
testcase_28 AC 2 ms
5,376 KB
testcase_29 AC 1 ms
5,376 KB
testcase_30 AC 2 ms
5,376 KB
testcase_31 AC 2 ms
5,376 KB
testcase_32 AC 2 ms
5,376 KB
testcase_33 AC 1 ms
5,376 KB
testcase_34 AC 1 ms
5,376 KB
testcase_35 AC 2 ms
5,376 KB
testcase_36 AC 1 ms
5,376 KB
testcase_37 AC 2 ms
5,376 KB
testcase_38 AC 1 ms
5,376 KB
testcase_39 AC 2 ms
5,376 KB
testcase_40 AC 1 ms
5,376 KB
testcase_41 AC 1 ms
5,376 KB
testcase_42 AC 1 ms
5,376 KB
testcase_43 AC 1 ms
5,376 KB
testcase_44 AC 1 ms
5,376 KB
testcase_45 AC 2 ms
5,376 KB
testcase_46 AC 2 ms
5,376 KB
testcase_47 AC 1 ms
5,376 KB
testcase_48 AC 2 ms
5,376 KB
testcase_49 AC 2 ms
5,376 KB
testcase_50 AC 2 ms
5,376 KB
testcase_51 AC 2 ms
5,376 KB
testcase_52 AC 2 ms
5,376 KB
testcase_53 AC 2 ms
5,376 KB
testcase_54 AC 1 ms
5,376 KB
testcase_55 AC 1 ms
5,376 KB
testcase_56 AC 2 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

 bool TEST = false;

using namespace std;
#include<bits/stdc++.h>
#include<fstream>

#define rep(i,n) for(ll (i)=0;(i)<(ll)(n);i++)
#define rrep(i,n) for(ll (i)=(ll)(n)-1;(i)>=0;i--)
#define range(i,start,end,step) for(ll (i)=start;(i)<(ll)(end);(i)+=(step))
#define rrange(i,start,end,step) for(ll (i)=start;(i)>(ll)(end);(i)+=(step))

#define dump(x)  cerr << "Line " << __LINE__ << ": " <<  #x << " = " << (x) << "\n";
#define spa << " " <<
#define fi first
#define se second
#define all(a)  (a).begin(),(a).end()
#define allr(a)  (a).rbegin(),(a).rend()
template <typename T>
T SUM(vector<T> &A) {
  T sum = T(0);
  for (auto &&a: A) sum += a;
  return sum;
}
#define MIN(v) *min_element(all(v))
#define MAX(v) *max_element(all(v))

using ld = long double;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pdd = pair<ld, ld>;
 
template<typename T> using V = vector<T>;
template<typename T> using VV = V<V<T>>;
template<typename T, typename T2> using P = pair<T, T2>;
template<typename T, typename T2> using UM = unordered_map<T, T2>;
template<typename T> using PQ = priority_queue<T, V<T>, greater<T>>;
template<typename T> using rPQ = priority_queue<T, V<T>, less<T>>;
template<class T>vector<T> make_vec(size_t a){return vector<T>(a);}
template<class T, class... Ts>auto make_vec(size_t a, Ts... ts){return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));}
template<class SS, class T> ostream& operator << (ostream& os, const pair<SS, T> v){os << "(" << v.first << ", " << v.second << ")"; return os;}
template<typename T> ostream& operator<<(ostream &os, const vector<T> &v) { for (auto &e : v) os << e << ' '; return os; }
template<class T> ostream& operator<<(ostream& os, const vector<vector<T>> &v){ for(auto &e : v){os << e << "\n";} return os;}
struct fast_ios { fast_ios(){ cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
 
template <class T> void UNIQUE(vector<T> &x) {sort(all(x));x.erase(unique(all(x)), x.end());}
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
void fail() { cout << -1 << '\n'; exit(0); }
inline int popcount(const int x) { return __builtin_popcount(x); }
inline int popcount(const ll x) { return __builtin_popcountll(x); }
template<typename T> void debug(vector<vector<T>>&v){for(ll i=0;i<v.size();i++)
{cerr<<v[i][0];for(ll j=1;j<v[i].size();j++)cerr spa v[i][j];cerr<<"\n";}};
template<typename T> void debug(vector<T>&v){if(v.size()!=0)cerr<<v[0];
for(ll i=1;i<v.size();i++)cerr spa v[i];
cerr<<"\n";};
template<typename T> void debug(priority_queue<T>&v){V<T> vals; while(!v.empty()) {cerr << v.top() << " "; vals.push_back(v.top()); v.pop();} cerr<<"\n"; for(auto val: vals) v.push(val);}
template<typename T, typename T2> void debug(map<T,T2>&v){for(auto [k,v]: v) cerr << k spa v << "\n"; cerr<<"\n";}
template<typename T, typename T2> void debug(unordered_map<T,T2>&v){for(auto [k,v]: v) cerr << k spa v << "\n";cerr<<"\n";}
V<int> listrange(int n) {V<int> res(n); rep(i,n) res[i]=i; return res;}
string YES = "Yes";
string NO = "No";
void pans(bool v){if (v) cout << YES << "\n"; else cout << NO << "\n";}

template<typename T> P<T,T> divmod(T a, T b) {return make_pair(a/b, a%b);}

const ll INF = (1ll<<62);
// const ld EPS   = 1e-10;
// const ld PI    = acos(-1.0);

template< int mod >
struct ModInt {
  int x;

  ModInt() : x(0) {}

  ModInt(int64_t y) : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {}

  ModInt &operator+=(const ModInt &p) {
    if((x += p.x) >= mod) x -= mod;
    return *this;
  }

  ModInt &operator-=(const ModInt &p) {
    if((x += mod - p.x) >= mod) x -= mod;
    return *this;
  }

  ModInt &operator*=(const ModInt &p) {
    x = (int) (1LL * x * p.x % mod);
    return *this;
  }

  ModInt &operator/=(const ModInt &p) {
    *this *= p.inverse();
    return *this;
  }

  ModInt operator-() const { return ModInt(-x); }

  ModInt operator+(const ModInt &p) const { return ModInt(*this) += p; }

  ModInt operator-(const ModInt &p) const { return ModInt(*this) -= p; }

  ModInt operator*(const ModInt &p) const { return ModInt(*this) *= p; }

  ModInt operator/(const ModInt &p) const { return ModInt(*this) /= p; }

  bool operator==(const ModInt &p) const { return x == p.x; }

  bool operator!=(const ModInt &p) const { return x != p.x; }

  ModInt inverse() const {
    int a = x, b = mod, u = 1, v = 0, t;
    while(b > 0) {
      t = a / b;
      swap(a -= t * b, b);
      swap(u -= t * v, v);
    }
    return ModInt(u);
  }

  ModInt pow(int64_t n) const {
    ModInt ret(1), mul(x);
    while(n > 0) {
      if(n & 1) ret *= mul;
      mul *= mul;
      n >>= 1;
    }
    return ret;
  }

  friend ostream &operator<<(ostream &os, const ModInt &p) {
    return os << p.x;
  }

  friend istream &operator>>(istream &is, ModInt &a) {
    int64_t t;
    is >> t;
    a = ModInt< mod >(t);
    return (is);
  }

  static int get_mod() { return mod; }
};

using m17 = ModInt<1'000'000'007>;
using m98 = ModInt<998'244'353>;
using MOD = m98;
ll mod = 998'244'353;
// using MOD = m17;
// ll mod = 1'000'000'007;


V<MOD> g1;
V<MOD> g2;
V<MOD> inverse;
void prepare(int n) {
  chmax(n,10);
  int s = max(2, (int)g1.size());
  g1.resize(n+1);
  g2.resize(n+1);
  inverse.resize(n+1);
  g1[0] = g1[1] = g2[0] = g2[1] = 1;
  inverse[0] = 0;
  inverse[1] = 1;
  range(i,s,n+1,1) {
    g1[i] = g1[i-1]*i;
    inverse[i] = -inverse[mod%i]*(mod/i);
    g2[i] = g2[i-1]*inverse[i];
  }
}
template<typename T>
MOD cmb(T n, T r) {
  if (r<0 || r>n) return 0;
  if (g1.size()<=n) prepare(n);
  r = min(r, n-r);
  return g1[n]*g2[r]*g2[n-r];
}
template<typename T>
MOD perm(T n, T r) {
  if (r<0 || r>n) return 0;
  if (g1.size()<=n) prepare(n);
  return g1[n]*g2[n-r];
}

void Main(){
    ll n,m;
    cin >> n >> m;
    if (m<0) m *= -1;
    V<ll> a(n);
    MOD ans = 0;
    auto sub = [&](ll a) {
        if ((n+a)&1) return (MOD)0;
        ll p = (n+a)/2;
        return cmb((ll)n,(ll)p);
    };
    if (m==0) {
        // cout << sub(0) << endl;
        MOD prob = sub(0) / MOD(2).pow(n);
        ans = MOD(1) - (MOD(1) - prob) * (MOD(1) - prob);
    } else {
        range(a, 1, m+1, 1) {
            if (a*a>m) break;
            if (m%a!=0) continue;
            ll b = m/a;
            MOD val = sub(a) * sub(b);
            if (a!=b) val *= 2;
            ans += val;
        }
        ans *= 2;
        ans /= MOD(4).pow(n);
    }
    cout << ans << "\n";
}

int main(void){
    std::ifstream in("tmp_in");
    if (TEST) {
        std::cin.rdbuf(in.rdbuf());
        std::cout << std::fixed << std::setprecision(15);
    } else {
        std::cin.tie(nullptr);
        std::ios_base::sync_with_stdio(false);
        std::cout << std::fixed << std::setprecision(15);
    }
    Main();
}
0