結果

問題 No.215 素数サイコロと合成数サイコロ (3-Hard)
ユーザー tko919tko919
提出日時 2020-03-30 01:41:17
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 10,112 bytes
コンパイル時間 2,679 ms
コンパイル使用メモリ 205,660 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-06-10 19:45:08
合計ジャッジ時間 3,591 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 RE -
testcase_01 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

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

//template
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(a);i>(b);i--)
#define ALL(v) (v).begin(),(v).end()
typedef long long int ll;
const int inf = 0x3fffffff; const ll INF = 0x1fffffffffffffff; const double eps=1e-12;
void tostr(ll x,string& res){while(x)res+=('0'+(x%10)),x/=10; reverse(ALL(res)); return;}
template<class T> inline bool chmax(T& a,T b){ if(a<b){a=b;return 1;}return 0; }
template<class T> inline bool chmin(T& a,T b){ if(a>b){a=b;return 1;}return 0; }
//template end

template<unsigned mod=1000000007>struct mint {
   unsigned val;
   static unsigned get_mod(){return mod;}
   unsigned inv() const{
      int tmp,a=val,b=mod,x=1,y=0;
      while(b)tmp=a/b,a-=tmp*b,swap(a,b),x-=tmp*y,swap(x,y);
      if(x<0)x+=mod; return x;
   }
   mint():val(0){}
   mint(ll x):val(x>=0?x%mod:mod+(x%mod)){}
   mint pow(ll t){mint res=1,b=*this; while(t){if(t&1)res*=b;b*=b;t>>=1;}return res;}
   mint& operator+=(const mint& x){if((val+=x.val)>=mod)val-=mod;return *this;}
   mint& operator-=(const mint& x){if((val+=mod-x.val)>=mod)val-=mod; return *this;}
   mint& operator*=(const mint& x){val=ll(val)*x.val%mod; return *this;}
   mint& operator/=(const mint& x){val=ll(val)*x.inv()%mod; return *this;}
   mint operator+(const mint& x)const{return mint(*this)+=x;}
   mint operator-(const mint& x)const{return mint(*this)-=x;}
   mint operator*(const mint& x)const{return mint(*this)*=x;}
   mint operator/(const mint& x)const{return mint(*this)/=x;}
   bool operator==(const mint& x)const{return val==x.val;}
   bool operator!=(const mint& x)const{return val!=x.val;}
};
template<unsigned mod=1000000007>struct factorial {
   using Mint=mint<mod>;
   vector<Mint> Fact,Finv,Inv;
public:
   factorial(int maxx){
      Fact.resize(maxx+1),Finv.resize(maxx+1); Inv.resize(maxx+1);
      Fact[0]=Inv[1]=Mint(1); rep(i,0,maxx)Fact[i+1]=Fact[i]*(i+1);
      Finv[maxx]=Mint(1)/Fact[maxx]; rrep(i,maxx,0)Finv[i-1]=Finv[i]*i;
      rep(i,2,maxx+1)Inv[i]=Inv[mod%i]*(mod-mod/i);
   }
   Mint fact(int n,bool inv=0){if(inv)return Finv[n];else return Fact[n];}
   Mint inv(int n){return Inv[n];}
   Mint nPr(int n,int r){if(n<0||n<r||r<0)return Mint(0);else return Fact[n]*Finv[n-r];}
   Mint nCr(int n,int r){if(n<0||n<r||r<0)return Mint(0);else return Fact[n]*Finv[r]*Finv[n-r];}
}; using Mint=mint<>; using Factorial=factorial<>;

vector<int> rt,irt;
template<unsigned mod=998244353,unsigned p=3>void init(int lg=21){
   using Mint=mint<mod>; Mint prt=p;
   rt.resize(1<<lg,1); irt.resize(1<<lg,1);
   rep(w,0,lg){
      int mask=(1<<w)-1,t=Mint(-1).val>>w;
      Mint g=prt.pow(t),ig=prt.pow(mod-1-t);
      rep(i,0,mask){
         rt[mask+i+1]=(g*rt[mask+i]).val;
         irt[mask+i+1]=(ig*irt[mask+i]).val;
      }
   }
}

template<unsigned mod=998244353>struct FPS{
   using Mint=mint<mod>; vector<Mint> f;
   FPS():f({1}){}
   FPS(int _n):f(_n){}
   FPS(vector<Mint> _f):f(_f){}
   Mint& operator[](const int i){return f[i];}
   Mint eval(Mint x){
      Mint res,w=1;
      for(Mint v:f)res+=w*v,w*=x; return res;
   }
   void ntt(bool inv=0){
        int n=f.size(); if(n==1)return;
        if(inv){
            for(int i=1;i<n;i<<=1){
                for(int j=0;j<n;j+=i*2){
                    rep(k,0,i){
                        f[i+j+k]*=irt[i*2-1+k];
                        const Mint tmp=f[j+k]-f[i+j+k];
                        f[j+k]+=f[i+j+k]; f[i+j+k]=tmp;
                    }
                }
            }
            Mint mul=Mint(n).inv(); rep(i,0,n)f[i]*=mul;
        }else{
            for(int i=n>>1;i;i>>=1){
                for(int j=0;j<n;j+=i*2){
                    rep(k,0,i){
                        const Mint tmp=f[j+k]-f[i+j+k];
                        f[j+k]+=f[i+j+k]; f[i+j+k]=tmp*rt[i*2-1+k];
                    }
                }
            }
        }
   }
   FPS inv()const{
      assert(f[0]!=0); int n=f.size();
      FPS res(n); res.f[0]=f[0].inv();
      for(int k=1;k<n;k<<=1){
         FPS g(k*2),h(k*2);
         rep(i,0,min(k*2,n))g[i]=f[i]; rep(i,0,k)h[i]=res[i];
         g.ntt(); h.ntt(); rep(i,0,k*2)g[i]*=h[i]; g.ntt(1);
         rep(i,0,k)g[i]=0,g[i+k]*=-1;
         g.ntt(); rep(i,0,k*2)g[i]*=h[i]; g.ntt(1);
         rep(i,k,min(k*2,n))res[i]=g[i];
      } return res;
   }
   FPS operator+(const FPS& g)const{return FPS(*this)+=g;}
   FPS operator-(const FPS& g)const{return FPS(*this)-=g;}
   FPS operator*(const FPS& g)const{return FPS(*this)*=g;}
   template<class T>FPS operator*(T t)const{return FPS(*this)*=t;}
   FPS operator/(const FPS& g)const{return FPS(*this)/=g;}
   template<class T>FPS operator/(T t)const{return FPS(*this)/=t;}
   FPS operator%(const FPS& g)const{return FPS(*this)%=g;}
   FPS& operator+=(FPS g){
      if(g.f.size()>f.size())f.resize(g.f.size());
      rep(i,0,g.f.size())f[i]+=g[i]; return *this;
   }
   FPS& operator-=(FPS g){
      if(g.f.size()>f.size())f.resize(g.f.size());
      rep(i,0,g.f.size())f[i]-=g[i]; return *this;
   }
   FPS& operator*=(FPS g){
      int m=f.size()+g.f.size()-1,n=1; while(n<m)n<<=1;
      f.resize(n); g.f.resize(n);
      ntt(); g.ntt(); rep(i,0,n)f[i]*=g[i]; 
      ntt(1); f.resize(m); return *this;
   }
   template<class T>FPS& operator*=(T t){for(Mint x:f)x*=t; return *this;}
   FPS& operator/=(FPS g){
      if(g.f.size()>f.size())return *this=FPS({0});
      reverse(ALL(f)); reverse(ALL(g.f));
      int n=f.size()-g.f.size()+1;
      f.resize(n); g.f.resize(n); FPS mul=g.inv();
      *this*=mul; f.resize(n); reverse(ALL(f)); return *this;
   }
   template<class T>FPS& operator/=(T t){for(Mint x:f)x/=t; return *this;}
   FPS& operator%=(FPS g){
      *this-=*this/g*g;
      while(!f.empty()&&f.back()==0)f.pop_back();
      return *this;
   }
   FPS pow(ll k){
      int n=f.size(); FPS ff=*this,res;
      while(k){
         if(k&1){res*=ff; res.f.resize(n);}
         ff*=ff; ff.f.resize(n); k>>=1;
      } return res;
   }
   FPS sqrt(){
      int n=f.size(); FPS res(1); res[0]=1;
      for(int k=1;k<n;k<<=1){
         FPS ff=*this; res.f.resize(k*2);
         res+=ff/res; res/=2;
      } res.f.resize(n); return res;
   }
   FPS diff(){
      FPS res=*this; rep(i,0,res.f.size()-1)res[i]=res[i+1]*(i+1);
      res.f.pop_back(); return res;
   }
   FPS inte(){
      FPS res=*this; res.f.push_back(0);
      rrep(i,res.f.size()-1,0)res[i]=res[i-1]/i;
      res[0]=0; return res;
   }
   FPS log(){
      assert(f[0]==1); FPS res=diff()*inv(); 
      res.f.resize(f.size()-1); res=res.inte(); return res;
   }
   FPS exp(){
      assert(f[0]==0); int m=f.size(),n=1; while(n<m)n<<=1;
      f.resize(n); FPS d=diff(),res(n); vector<FPS> pre;
      for(int k=n;k;k>>=1){
         FPS g=d; g.f.resize(k);
         g.ntt(); pre.push_back(g);
      }
      auto dfs=[&](auto dfs,int l,int r,int dep)->void{
         if(r-l==1){if(l>0)res[l]/=l; return;}
         int m=(l+r)>>1; dfs(dfs,l,m,dep+1);
         FPS g(r-l); rep(i,0,m-l)g[i]=res[l+i];
         g.ntt(); rep(i,0,r-l)g[i]*=pre[dep][i]; g.ntt(1);
         rep(i,m,r)res[i]+=g[i-l-1]; dfs(dfs,m,r,dep+1);
      }; res[0]=1; dfs(dfs,0,n,0); res.f.resize(m); return res;
   }
};//need to initialize

using M1=mint<1045430273>; using M2=mint<1051721729>; using M3=mint<1053818881>;
vector<Mint> conv(vector<Mint> a,vector<Mint> b){
   int n=a.size()+b.size()-1; vector<Mint> res(n);
   if(a.size()*b.size()<=12000000){
      rep(i,0,a.size())rep(j,0,b.size())res[i+j]+=a[i]*b[j];
      return res;
   }
   vector<ll> vals[3];
   init<1045430273,3>();
   FPS<1045430273> x1(a.size()),y1(b.size());
   rep(i,0,a.size())x1[i]=M1(a[i].val);
   rep(i,0,b.size())y1[i]=M1(b[i].val); x1*=y1;
   auto f=x1.f; for(auto v:f)vals[0].push_back(v.val);
   init<1051721729,6>();
   FPS<1051721729> x2(a.size()),y2(b.size());
   rep(i,0,a.size())x2[i]=M2(a[i].val);
   rep(i,0,b.size())y2[i]=M2(b[i].val); x2*=y2;
   auto g=x2.f; for(auto v:g)vals[1].push_back(v.val);
   init<1053818881,7>();
   FPS<1053818881> x3(a.size()),y3(b.size());
   rep(i,0,a.size())x3[i]=M3(a[i].val);
   rep(i,0,b.size())y3[i]=M3(b[i].val); x3*=y3;
   auto h=x3.f; for(auto v:h)vals[2].push_back(v.val);
   M2 r_12=M2(M1::get_mod()).inv();
   M3 r_13=M3(M1::get_mod()).inv(),r_23=M3(M2::get_mod()).inv();
   M3 r_1323=r_13*r_23;
   Mint w1(M1::get_mod()); Mint w2=w1*Mint(M2::get_mod());
   rep(i,0,n){
      ll a=vals[0][i],b=(vals[1][i]+M2::get_mod()-a)*r_12.val%M2::get_mod();
      ll c=((vals[2][i]+M3::get_mod()-a)*r_1323.val+
         (M3::get_mod()-b)*r_23.val)%M3::get_mod();
      res[i]=(a+b*w1.val+c*w2.val);
   } return res;
}

using fps=FPS<1000000007>;
int a[]={2,3,5,7,11,13},b[]={4,6,8,9,10,12};
ll n; int m;
Mint dp[2][51][700]; vector<Mint> g,gg;

vector<Mint> inv(vector<Mint> f){
   int n=f.size(); fps res(1); res[0]=f[0].inv();
   for(int k=1;k<n;k<<=1){
      fps ff(f); ff.f.resize(k*2);
      fps sub(conv(conv(res.f,res.f),ff.f));
      sub.f.resize(k*2); for(Mint& x:res.f)x*=2; res-=sub;
   } res.f.resize(n); return res.f;
}
vector<Mint> modg(vector<Mint> f){
   if(f.size()<g.size())return f;
   vector<Mint> ff=f; reverse(ALL(ff)); ff=conv(gg,ff);
   ff.resize(f.size()-g.size()+1); reverse(ALL(ff));
   fps r(f),sub(conv(g,ff)); sub.f.resize(f.size()); r-=sub;
   auto res=r.f; while(res.size()&&res.back()==0)res.pop_back();
   return res;
}
Mint ktms(ll t){
   gg=g; reverse(ALL(gg)); while(gg.size()&&gg.back()==0)gg.pop_back(); gg=inv(gg);
   vector<Mint> ret(1),mul(2); ret[0]=mul[1]=1;
   while(t){
      if(t&1)ret=modg(conv(ret,mul));
      mul=modg(conv(mul,mul)); t>>=1;
   } Mint res; for(auto x:ret)res+=x; return res;
}

int main(){
   int p,c; cin>>n>>p>>c;
   m=p*13+c*12; dp[0][0][0]=dp[1][0][0]=1;
   rep(k,0,6)rep(i,0,p)rep(j,0,p*13-a[k]+1)if(dp[0][i][j]!=0)dp[0][i+1][j+a[k]]+=dp[0][i][j];
   rep(k,0,6)rep(i,0,c)rep(j,0,c*12-b[k]+1)if(dp[1][i][j]!=0)dp[1][i+1][j+b[k]]+=dp[1][i][j];
   m++; g.resize(m); rep(i,0,p*13+1)rep(j,0,c*12+1)g[i+j]+=dp[0][p][i]*dp[1][c][j];
   reverse(ALL(g)); for(auto& x:g)x*=-1; g.back()=1;
   Mint res=ktms(n+m-2); printf("%d\n",res.val);
   return 0;
}
0