Artifact 0f56b30fe14df222d548c793ee7db108c5907f08
#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 <stack>
#include <cmath>
#include <cassert>
using namespace std;
typedef long long LL;
typedef long double LD;
typedef complex<LD> 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; }
vector<mint> FAC_(1,1);
mint FAC(LL n) { while( FAC_.size()<=n ) FAC_.push_back( FAC_.back()*FAC_.size() ); return FAC_[n]; }
//mint C(LL n, LL k) { return k<0 || n<k ? 0 : FAC(n) / (FAC(k) * FAC(n-k)); }
vector< vector<mint> > CP_;
mint C(LL n, LL k) {
while( CP_.size() <= n ) {
int nn = CP_.size();
CP_.push_back(vector<mint>(nn+1,1));
for(int kk=1; kk<nn; ++kk)
CP_[nn][kk] = CP_[nn-1][kk-1] + CP_[nn-1][kk];
}
return k<0 || n<k ? 0 : CP_[n][k];
}
int gcd(int a, int b) {
while(a)
swap(a, b%=a);
return b;
}
class Spacetsk { public:
int countsets(int L, int H, int K)
{
if( K==1 )
return (L+1)*(H+1);
mint sum = 0;
for(int x=0; x<=L; ++x)
for(int y=1; y<=H; ++y)
{
mint dup = (x==0 ? L+1 : 2*(L+1-x));
mint mid = C(gcd(x, y), K-1);
sum = sum + dup*mid;
}
return sum.val;
}
};
// 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(_, Spacetsk().countsets(L, H, K));}
int main(){
CASE(0)
int L = 1;
int H = 1;
int K = 2;
int _ = 4;
END
CASE(1)
int L = 1;
int H = 1;
int K = 1;
int _ = 4;
END
CASE(2)
int L = 2;
int H = 2;
int K = 1;
int _ = 9;
END
CASE(3)
int L = 2;
int H = 2;
int K = 2;
int _ = 23;
END
CASE(4)
int L = 5;
int H = 5;
int K = 3;
int _ = 202;
END
CASE(5)
int L = 561;
int H = 394;
int K = 20;
int _ = 786097180;
END
CASE(6)
int L = 1;
int H = 1;
int K = 1;
int _ = 4;
END
CASE(7)
int L = 2000;
int H = 2000;
int K = 500;
int _ = -1;
END
CASE(7)
int L = 2000;
int H = 2000;
int K = 2;
int _ = -1;
END
}
// END CUT HERE