結果

問題 No.1973 Divisor Sequence
ユーザー miscalcmiscalc
提出日時 2022-06-10 22:05:05
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 282 ms / 2,000 ms
コード長 2,640 bytes
コンパイル時間 4,842 ms
コンパイル使用メモリ 270,444 KB
実行使用メモリ 100,996 KB
最終ジャッジ日時 2023-10-21 06:20:36
合計ジャッジ時間 7,981 ms
ジャッジサーバーID
(参考情報)
judge9 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 165 ms
30,104 KB
testcase_03 AC 10 ms
5,580 KB
testcase_04 AC 96 ms
19,028 KB
testcase_05 AC 32 ms
16,720 KB
testcase_06 AC 101 ms
25,560 KB
testcase_07 AC 21 ms
7,088 KB
testcase_08 AC 55 ms
14,940 KB
testcase_09 AC 84 ms
16,984 KB
testcase_10 AC 107 ms
20,416 KB
testcase_11 AC 14 ms
5,532 KB
testcase_12 AC 82 ms
20,980 KB
testcase_13 AC 25 ms
8,476 KB
testcase_14 AC 51 ms
13,952 KB
testcase_15 AC 145 ms
22,052 KB
testcase_16 AC 141 ms
26,088 KB
testcase_17 AC 90 ms
17,512 KB
testcase_18 AC 7 ms
4,348 KB
testcase_19 AC 116 ms
22,112 KB
testcase_20 AC 21 ms
6,296 KB
testcase_21 AC 125 ms
30,576 KB
testcase_22 AC 118 ms
22,196 KB
testcase_23 AC 232 ms
100,996 KB
testcase_24 AC 282 ms
38,428 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
//*
#include <atcoder/all>
using namespace atcoder;
//using mint = modint998244353;
using mint = modint1000000007;
//*/
using ll = long long;
using ld = long double;
using pll = pair<ll, ll>;
using tlll = tuple<ll, ll, ll>;
constexpr ll INF = 1LL << 60;
template<class T> bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;}
template<class T> bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;}
ll safemod(ll A, ll M) {ll res = A % M; if (res < 0) res += M; return res;}
ll divfloor(ll A, ll B) {if (B < 0) {return divfloor(-A, -B);} return (A - safemod(A, B)) / B;}
ll divceil(ll A, ll B) {if (B < 0) {return divceil(-A, -B);} return divfloor(A + B - 1, B);}
ll mypowl(ll A, ll B) {ll res = 1; for (int i = 0; i < B; i++) {res *= A;} return res;}
template<class T> void unique(vector<T> &V) {V.erase(unique(V.begin(), V.end()), V.end());}
template<class T> void sortunique(vector<T> &V) {sort(V.begin(), V.end()); V.erase(unique(V.begin(), V.end()), V.end());}
#define FINALANS(A) do {cout << (A) << '\n'; exit(0);} while (false)
template<class T> void printvec(const vector<T> &V) {int _n = V.size(); for (int i = 0; i < _n; i++) cout << V[i] << (i == _n - 1 ? "" : " ");cout << '\n';}
template<class T> void printvect(const vector<T> &V) {for (auto v : V) cout << v << '\n';}
template<class T> void printvec2(const vector<vector<T>> &V) {for (auto &v : V) printvec(v);}

vector<pll> factorize(ll n)
{
  vector<pll> ret;
  for (ll p = 2; p * p <= n; p++)
  {
    ll e = 0;
    while (n % p == 0)
    {
      n /= p;
      e++;
    }
    if (e > 0)
      ret.emplace_back(make_pair(p, e));
  }
  if (n > 1)
    ret.emplace_back(make_pair(n, 1));
  return ret;
}

mint f(ll N, ll S)
{
  vector dp(N + 1, vector(S + 2, mint(0)));
  dp.at(0).at(0) = 1;
  for (ll i = 0; i < N; i++)
  {
    for (ll j = 0; j <= S; j++)
    {
      dp.at(i + 1).at(0) += dp.at(i).at(j);
      dp.at(i + 1).at(S - j + 1) -= dp.at(i).at(j);
    }
    for (ll j = 0; j < S; j++)
    {
      dp.at(i + 1).at(j + 1) += dp.at(i + 1).at(j);
    }
  }
  /*
  for (ll i = 0; i < N + 1; i++)
  {
    for (ll j = 0; j < S + 1; j++)
    {
      cout << i << " " << j << "  " << dp.at(i).at(j).val() << endl;
    }
  }
  //*/
  mint res = 0;
  for (ll j = 0; j <= S; j++)
  {
    mint tmp = dp.at(N).at(j);
    res += tmp;
  }
  return res;
}

int main()
{
  ll N, M;
  cin >> N >> M;

  auto pes = factorize(M);
  mint ans = 1;
  for (auto [p, e] : pes)
  {
    mint tmp = f(N, e);
    //cerr << p << " " << e << "  " << tmp.val() << endl;
    ans *= tmp;
  }
  cout << ans.val() << endl;
}
0