Artifact 1b6b6f1bf178804be92a8b0426cf17bc506de7e6
#include <iostream>
#include <sstream>
#include <iomanip>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <iterator>
#include <functional>
#include <complex>
#include <queue>
#include <valarray>
#include <stack>
#include <cmath>
#include <cassert>
#include <cstring>
using namespace std;
typedef long long LL;
typedef complex<double> CMP;
static const int MODVAL = 1000000007;
struct mint
{
int val;
mint():val(0){}
mint(int x):val(x%MODVAL) {}
mint(size_t x):val(x%MODVAL) {}
mint(LL x):val(x%MODVAL) {}
};
mint& operator+=(mint& x, mint y) { return x = x.val+y.val; }
mint& operator-=(mint& x, mint y) { return x = x.val-y.val+MODVAL; }
mint& operator*=(mint& x, mint y) { return x = LL(x.val)*y.val; }
mint POW(mint x, LL e) { mint v=1; for(;e;x*=x,e>>=1) if(e&1) v*=x; return v; }
mint& operator/=(mint& x, mint y) { return x *= POW(y, MODVAL-2); }
mint operator+(mint x, mint y) { return x+=y; }
mint operator-(mint x, mint y) { return x-=y; }
mint operator*(mint x, mint y) { return x*=y; }
mint operator/(mint x, mint y) { return x/=y; }
mint inv2 = mint(1) / 2;
class Nim { public:
int count(int K, int L)
{
valarray<mint> v(65536);
v[slice(2,L-1,1)] = 1;
for(unsigned p=2; p<=L; ++p)
if( v[p].val )
for(unsigned q=p*p; q<=L; q+=p)
v[q] = 0;
pre(v, 0, 65536);
valarray<mint> a(1, 65536);
for(int i=1; i<=K; i<<=1, v*=v)
if( K & i )
a *= v;
post(a, 0, 65536);
return a[0].val;
}
void pre(valarray<mint>& v, int s, int e)
{
if( s+1 == e )
return;
int m = (s+e)/2;
pre(v, s, m);
pre(v, m, e);
for(int i=s,j=m; i<m; ++i,++j) {
mint vi=v[i], vj=v[j];
v[i] = vi - vj;
v[j] = vi + vj;
}
}
void post(valarray<mint>& v, int s, int e)
{
if( s+1 == e )
return;
int m = (s+e)/2;
for(int i=s,j=m; i<m; ++i,++j) {
mint dif=v[i], sum=v[j];
v[i] = (sum + dif) * inv2;
v[j] = (sum - dif) * inv2;
}
post(v, s, m);
post(v, m, e);
}
};
// BEGIN CUT HERE
#include <ctime>
double start_time; string timer()
{ ostringstream os; os << " (" << int((clock()-start_time)/CLOCKS_PER_SEC*1000) << " msec)"; return os.str(); }
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v)
{ os << "{ ";
for(typename vector<T>::const_iterator it=v.begin(); it!=v.end(); ++it)
os << '\"' << *it << '\"' << (it+1==v.end() ? "" : ", "); os << " }"; return os; }
void verify_case(const int& Expected, const int& Received) {
bool ok = (Expected == Received);
if(ok) cerr << "PASSED" << timer() << endl; else { cerr << "FAILED" << timer() << endl;
cerr << "\to: \"" << Expected << '\"' << endl << "\tx: \"" << Received << '\"' << endl; } }
#define CASE(N) {cerr << "Test Case #" << N << "..." << flush; start_time=clock();
#define END verify_case(_, Nim().count(K, L));}
int main(){
CASE(0)
int K = 3;
int L = 7;
int _ = 6;
END
CASE(1)
int K = 4;
int L = 13;
int _ = 120;
END
CASE(2)
int K = 10;
int L = 100;
int _ = 294844622;
END
CASE(3)
int K = 123456789;
int L = 12345;
int _ = 235511047;
END
CASE(4)
int K = 1000000000;
int L = 50000;
int _ = 428193537;
END
/*
CASE(5)
int K = ;
int L = ;
int _ = ;
END
*/
}
// END CUT HERE