結果

問題 No.1973 Divisor Sequence
ユーザー eQeeQe
提出日時 2024-12-22 20:01:18
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 597 ms / 2,000 ms
コード長 7,845 bytes
コンパイル時間 6,269 ms
コンパイル使用メモリ 336,292 KB
実行使用メモリ 100,736 KB
最終ジャッジ日時 2024-12-22 20:01:30
合計ジャッジ時間 9,760 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,248 KB
testcase_02 AC 161 ms
29,792 KB
testcase_03 AC 9 ms
5,632 KB
testcase_04 AC 97 ms
18,696 KB
testcase_05 AC 22 ms
16,640 KB
testcase_06 AC 102 ms
25,320 KB
testcase_07 AC 18 ms
6,912 KB
testcase_08 AC 52 ms
14,824 KB
testcase_09 AC 86 ms
16,652 KB
testcase_10 AC 105 ms
20,204 KB
testcase_11 AC 17 ms
5,504 KB
testcase_12 AC 84 ms
20,844 KB
testcase_13 AC 25 ms
8,192 KB
testcase_14 AC 50 ms
11,904 KB
testcase_15 AC 141 ms
21,840 KB
testcase_16 AC 137 ms
26,104 KB
testcase_17 AC 88 ms
17,384 KB
testcase_18 AC 6 ms
5,248 KB
testcase_19 AC 116 ms
21,896 KB
testcase_20 AC 20 ms
6,412 KB
testcase_21 AC 124 ms
30,324 KB
testcase_22 AC 116 ms
21,828 KB
testcase_23 AC 597 ms
100,736 KB
testcase_24 AC 286 ms
38,312 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
#include<atcoder/all>
using namespace std;
namespace my{
using ml=atcoder::modint1000000007;
auto&operator>>(istream&i,ml&x){int t;i>>t;x=t;return i;}
auto&operator<<(ostream&o,const ml&x){return o<<(int)x.val();}
#define eb emplace_back
#define LL(...) ll __VA_ARGS__;lin(__VA_ARGS__)
#define FO(n) for(ll ij=n;ij-->0;)
#define FOR(i,...) for(auto[i,i##stop,i##step]=range(0,__VA_ARGS__);i<i##stop;i+=i##step)
#define fo(i,...) FO##__VA_OPT__(R)(i __VA_OPT__(,__VA_ARGS__))
#define fe(a,i,...) for(auto&&__VA_OPT__([)i __VA_OPT__(,__VA_ARGS__]):a)
#define single_testcase void solve();}int main(){my::io();my::solve();}namespace my{
void io(){cin.tie(nullptr)->sync_with_stdio(0);cout<<fixed<<setprecision(15);}
using ll=long long;
using ull=unsigned long long;
using ulll=__uint128_t;
using lll=__int128_t;
istream&operator>>(istream&i,ulll&x){ull t;i>>t;x=t;return i;}
ostream&operator<<(ostream&o,const ulll&x){return(x<10?o:o<<x/10)<<ll(x%10);}
istream&operator>>(istream&i,lll&x){ll t;i>>t;x=t;return i;}
ostream&operator<<(ostream&o,const lll&x){return o<<string(x<0,'-')<<ulll(x>0?x:-x);}
constexpr auto range(bool s,auto...a){array<ll,3>r{0,0,1};ll I=0;((r[I++]=a),...);if(!s&&I==1)swap(r[0],r[1]);r[0]-=s;return r;}
constexpr char newline=10;
constexpr char space=32;
lll pow(lll x,ll n){assert(n>=0);lll r=1;while(n)n&1?r*=x:r,x*=x,n>>=1;return r;}

template<class A,class B>struct pair{
  A a;B b;
  pair()=default;
  pair(A a,B b):a(a),b(b){}
  pair(const std::pair<A,B>&p):a(p.first),b(p.second){}
  auto operator<=>(const pair&)const=default;
  pair operator+(const pair&p)const{return{a+p.a,b+p.b};}
  friend ostream&operator<<(ostream&o,const pair&p){return o<<p.a<<space<<p.b;}
};

template<class F=less<>>auto&sort(auto&a,const F&f={}){ranges::sort(a,f);return a;}

template<class T,class U>ostream&operator<<(ostream&o,const std::pair<T,U>&p){return o<<p.first<<space<<p.second;}
template<class T,size_t n>ostream&operator<<(ostream&o,const array<T,n>&a){fo(i,n)o<<a[i]<<string(i!=n-1,space);return o;}

template<class V>concept vectorial=is_base_of_v<vector<typename V::value_type>,V>;
template<class T>struct vec_attr{using core_type=T;static constexpr int d=0;};
template<vectorial V>struct vec_attr<V>{using core_type=typename vec_attr<typename V::value_type>::core_type;static constexpr int d=vec_attr<typename V::value_type>::d+1;};
template<class T>using core_t=vec_attr<T>::core_type;
template<class V>istream&operator>>(istream&i,vector<V>&v){fe(v,e)i>>e;return i;}
template<class V>ostream&operator<<(ostream&o,const vector<V>&v){fe(v,e)o<<e<<string(&e!=&v.back(),vectorial<V>?newline:space);return o;}

template<class V>struct vec:vector<V>{
  using vector<V>::vector;
  vec(const vector<V>&v){vector<V>::operator=(v);}

  vec&operator^=(const vec&u){this->insert(this->end(),u.begin(),u.end());return*this;}
  vec operator^(const vec&u)const{return vec{*this}^=u;}
  vec&operator+=(const vec&u){vec&v=*this;fo(i,v.size())v[i]+=u[i];return v;}
  vec&operator-=(const vec&u){vec&v=*this;fo(i,v.size())v[i]-=u[i];return v;}
  vec operator+(const vec&u)const{return vec{*this}+=u;}
  vec operator-(const vec&u)const{return vec{*this}-=u;}
  vec&operator++(){fe(*this,e)++e;return*this;}
  vec&operator--(){fe(*this,e)--e;return*this;}
  vec operator-()const{vec v=*this;fe(v,e)e=-e;return v;}

  auto scan(const auto&f)const{pair<core_t<V>,bool>r{};fe(*this,e)if constexpr(!vectorial<V>)r.b?f(r.a,e),r:r={e,1};else if(auto s=e.scan(f);s.b)r.b?f(r.a,s.a),r:r=s;return r;}
  auto sum()const{return scan([](auto&a,const auto&b){a+=b;}).a;}
};
template<class T=ll,size_t n,size_t i=0>auto make_vec(const ll(&s)[n],T x={}){if constexpr(n==i+1)return vec<T>(s[i],x);else{auto X=make_vec<T,n,i+1>(s,x);return vec<decltype(X)>(s[i],X);}}

void lin(auto&...a){(cin>>...>>a);}
template<char c=space>void pp(const auto&...a){ll n=sizeof...(a);((cout<<a<<string(--n>0,c)),...);cout<<newline;}

template<class T,class U=T>auto rle(const vec<T>&a){vec<pair<T,U>>r;fe(a,e)r.size()&&e==r.back().a?++r.back().b:r.eb(e,1).b;return r;}
template<class T,class U=T>auto rce(vec<T>a){return rle<T,U>(sort(a));}

struct montgomery64{
  using modular=montgomery64;
  using i64=__int64_t;
  using u64=__uint64_t;
  using u128=__uint128_t;

  static inline u64 N;
  static inline u64 N_inv;
  static inline u64 R2;

  static int set_mod(u64 N){
    if(modular::N==N)return 0;
    assert(N<(1ULL<<63));
    assert(N&1);
    modular::N=N;
    R2=-u128(N)%N;
    N_inv=N;
    fo(5)N_inv*=2-N*N_inv;
    assert(N*N_inv==1);
    return 0;
  }
  static inline int init=set_mod(998244353);

  static u64 mod(){return N;}

  u64 a;
  montgomery64(const i64&a=0):a(reduce((u128)(a%(i64)N+N)*R2)){}

  static u64 reduce(const u128&T){
    u128 r=(T+u128(u64(T)*-N_inv)*N)>>64;
    return r>=N?r-N:r;
  }

  auto&operator+=(const modular&b){if((a+=b.a)>=N)a-=N;return*this;}
  auto&operator-=(const modular&b){if(i64(a-=b.a)<0)a+=N;return*this;}
  auto&operator*=(const modular&b){a=reduce(u128(a)*b.a);return*this;}
  auto&operator/=(const modular&b){*this*=b.inv();return*this;}

  friend auto operator+(const modular&a,const modular&b){return modular{a}+=b;}
  friend auto operator-(const modular&a,const modular&b){return modular{a}-=b;}
  friend auto operator*(const modular&a,const modular&b){return modular{a}*=b;}
  friend auto operator/(const modular&a,const modular&b){return modular{a}/=b;}
  friend bool operator==(const modular&a,const modular&b){return a.a==b.a;}
  auto operator-()const{return modular{}-modular{*this};}

  modular pow(u128 n)const{
    modular r{1},x{*this};
    while(n){
      if(n&1)r*=x;
      x*=x;
      n>>=1;
    }
    return r;
  }

  modular inv()const{u64 a=val(),b=N,u=1,v=0;assert(gcd(a,b)==1);while(b)swap(u-=a/b*v,v),swap(a-=a/b*b,b);return u;}
  u64 val()const{return reduce(a);}

  friend istream&operator>>(istream&i,montgomery64&b){ll t;i>>t;b=t;return i;}
  friend ostream&operator<<(ostream&o,const montgomery64&b){return o<<b.val();}
};

ll rand(auto...a){array<ll,2>v{};ll I=0;((v[I++]=a),...);auto[l,r]=v;if(I==1)swap(l,r);static ll t=495;t^=t<<7,t^=t>>9;return l<r?(t%(r-l)+(t%(r-l)<0?r-l:0))+l:t;}

bool miller_rabin(ll n,vec<ll>as){
  ll d=n-1;
  while(~d&1)d>>=1;

  using modular=montgomery64;
  auto pre_mod=modular::mod();
  modular::set_mod(n);

  modular one=1,minus_one=n-1;
  fe(as,a){
    if(a%n==0)continue;
    ll t=d;
    modular y=modular(a).pow(t);
    while(t!=n-1&&y!=one&&y!=minus_one)y*=y,t<<=1;
    if(y!=minus_one&&~t&1)return modular::set_mod(pre_mod),0;
  }
  return modular::set_mod(pre_mod),1;
}

bool is_prime(ll n){
  if(~n&1)return n==2;
  if(n<=1)return 0;
  if(n<4759123141LL)return miller_rabin(n,{2,7,61});
  return miller_rabin(n,{2,325,9375,28178,450775,9780504,1795265022});
}

ll pollard_rho(ll n){
  if(~n&1)return 2;
  if(is_prime(n))return n;

  using modular=montgomery64;
  auto pre_mod=modular::mod();
  modular::set_mod(n);

  modular R,one=1;
  auto f=[&](const modular&x){return x*x+R;};
  while(1){
    modular x,y,ys,q=one;
    R=rand(2,n),y=rand(2,n);
    ll g=1;
    constexpr ll m=128;
    for(ll r=1;g==1;r<<=1){
      x=y;
      fo(r)y=f(y);
      for(ll k=0;g==1&&k<r;k+=m){
        ys=y;
        for(ll i=0;i<m&&i<r-k;++i)q*=x-(y=f(y));
        g=std::gcd(q.val(),n);
      }
    }
    if(g==n)do g=std::gcd((x-(ys=f(ys))).val(),n);while(g==1);
    if(g!=n)return modular::set_mod(pre_mod),g;
  }
}

auto factorize(ll n){
  assert(n>0);
  auto f=[](auto&f,ll m){
    if(m==1)return vec<ll>{};
    ll d=pollard_rho(m);
    return d==m?vec<ll>{d}:f(f,d)^f(f,m/d);
  };
  return rce(f(f,n));
}

single_testcase
void solve(){
  LL(N,M);

  ml ans=1;
  fe(factorize(M),p,e){
    auto dp=make_vec({N+1,e+1},ml{});
    dp[0][0]=1;
    fo(i,N)fo(j,e+1)fo(k,e-j+1)dp[i+1][k]+=dp[i][j];
    ans*=dp[N].sum();
  }
  pp(ans);
}}
0