結果

問題 No.213 素数サイコロと合成数サイコロ (3-Easy)
ユーザー nola_suznola_suz
提出日時 2015-05-22 23:08:09
言語 C++11
(gcc 11.4.0)
結果
TLE  
実行時間 -
コード長 3,886 bytes
コンパイル時間 1,002 ms
コンパイル使用メモリ 97,880 KB
実行使用メモリ 12,620 KB
最終ジャッジ日時 2023-09-20 09:58:46
合計ジャッジ時間 9,486 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <set>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstdio>
#include <cstring>
#include <iterator>
#include <bitset>
#include <unordered_set>
#include <unordered_map>
//#include <utility>
//#include <memory>
//#include <functional>
//#include <deque>
//#include <cctype>
//#include <ctime>
//#include <numeric>
//#include <list>
//#include <iomanip>

//#if __cplusplus >= 201103L
//#include <array>
//#include <tuple>
//#include <initializer_list>
//#include <forward_list>
//
//#define cauto const auto&
//#else

//#endif

using namespace std;


typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;

#define VV(T) vector<vector< T > >

template <class T>
void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
    v.assign(a, vector<T>(b, t));
}

template <class F, class T>
void convert(const F &f, T &t){
    stringstream ss;
    ss << f;
    ss >> t;
}


#define reep(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) reep((i),0,(n))
#define ALL(v) (v).begin(),(v).end()
#define PB push_back
#define F first
#define S second
#define mkp make_pair
#define RALL(v) (v).rbegin(),(v).rend()
#define DEBUG
#ifdef DEBUG
#define dump(x)  cout << #x << " = " << (x) << endl;
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#else
#define dump(x) 
#define debug(x) 
#endif

#define MOD 1000000007LL
#define EPS 1e-8
static const int INF=1<<24;
int a[]={2,3,5,7,11,13};
int b[]={4,6,8,9,10,12};
vvll calc(vvll &aa,vvll &bb){
    vvll ret;
    initvv(ret,150,150);
    rep(i,150){
        rep(j,150){
            ll tt=0LL;
            rep(k,150){
                tt+=aa[i][k]*bb[k][j];
                tt%=MOD;
            }
            ret[i][j]=tt;
        }
    }
    return ret;
}
vvll foo(ll a,vvll &vv){
    vvll ret;
    initvv(ret,150,150,0LL);
    rep(i,150) ret[i][i]=1LL;
    while(a){
        if(a&1){
            ret=calc(ret,vv);
        }
        a/=2;
        vv=calc(vv,vv);
    }
    return ret;
}
vll foo2(vvll &vv,vll &a){
    vll ret(150,0LL);
    rep(i,150){
        rep(j,150){
            ret[i]+=vv[i][j]*a[149-i];
            ret[i]%=MOD;
        }
    }
    return ret;
}
vint cc;
void fa(int a){
    // if()
}
void mainmain(){
    ll n;
    cin>>n;
    ll aa,bb;
    cin>>aa>>bb;
    vvll vv;
    vll v(150,0);
    v[0]=1;
    bool f=false;
    if(n<150LL) f=true;
    ll ans=0;
    rep(i,aa){
        vll tmp(150,0);
        rep(j,150){
            if(v[j]){
                rep(k,6){
                    tmp[j+a[k]]+=v[j];
                    tmp[j+a[k]]%=MOD;
                }
            }
        }
        tmp.swap(v);
    }
    rep(i,bb){
        vll tmp(150,0);
        rep(j,150){
            if(v[j]){
                rep(k,6){
                    tmp[j+b[k]]+=v[j];
                    tmp[j+b[k]]%=MOD;
                }
            }
        }
        tmp.swap(v);
    }
    reep(i,n,150){
        ans+=v[i];
        ans%=MOD;
    }
    if(f){
        cout<<ans<<endl;
        return;
    }
    // rep(i,200) cout<<i<<" "<<v[i]<<endl;
    initvv(vv,150,150,0LL);
    reep(i,1,150){
        vv[i][i-1]=1LL;
    }
    rep(i,150){
        vv[0][i]=v[i+1];
    }
    vvll ttt=vv;
    foo(n-149LL,vv);
    v=foo2(vv,v);
    ans=0LL;
    ans+=v[149];
    v[149]=0LL;
    while(1){
        bool f=false;
        rep(i,150) if(v[i]) f=true;
        v=foo2(ttt,v);
        ans+=v[149];
        ans%=MOD;
        v[149]=0LL;
    }
    cout<<ans<<endl;
    // printf("%.13lf\n",ans);
}


signed main() {
    mainmain();
}
0