9f60383a2c 2012-06-16 kinaba: #include <iostream> 9f60383a2c 2012-06-16 kinaba: #include <sstream> 9f60383a2c 2012-06-16 kinaba: #include <iomanip> 9f60383a2c 2012-06-16 kinaba: #include <vector> 9f60383a2c 2012-06-16 kinaba: #include <string> 9f60383a2c 2012-06-16 kinaba: #include <map> 9f60383a2c 2012-06-16 kinaba: #include <set> 9f60383a2c 2012-06-16 kinaba: #include <algorithm> 9f60383a2c 2012-06-16 kinaba: #include <numeric> 9f60383a2c 2012-06-16 kinaba: #include <iterator> 9f60383a2c 2012-06-16 kinaba: #include <functional> 9f60383a2c 2012-06-16 kinaba: #include <complex> 9f60383a2c 2012-06-16 kinaba: #include <queue> 9f60383a2c 2012-06-16 kinaba: #include <stack> 9f60383a2c 2012-06-16 kinaba: #include <cmath> 9f60383a2c 2012-06-16 kinaba: #include <cassert> 9f60383a2c 2012-06-16 kinaba: using namespace std; 9f60383a2c 2012-06-16 kinaba: typedef long long LL; 9f60383a2c 2012-06-16 kinaba: typedef long double LD; 9f60383a2c 2012-06-16 kinaba: typedef complex<LD> CMP; 9f60383a2c 2012-06-16 kinaba: 9f60383a2c 2012-06-16 kinaba: static const int MODVAL = 1000000007; 9f60383a2c 2012-06-16 kinaba: struct mint 9f60383a2c 2012-06-16 kinaba: { 9f60383a2c 2012-06-16 kinaba: int val; 9f60383a2c 2012-06-16 kinaba: mint():val(0){} 9f60383a2c 2012-06-16 kinaba: mint(int x):val(x%MODVAL) {} 9f60383a2c 2012-06-16 kinaba: mint(size_t x):val(x%MODVAL) {} 9f60383a2c 2012-06-16 kinaba: mint(LL x):val(x%MODVAL) {} 9f60383a2c 2012-06-16 kinaba: }; 9f60383a2c 2012-06-16 kinaba: mint& operator+=(mint& x, mint y) { return x = x.val+y.val; } 9f60383a2c 2012-06-16 kinaba: mint& operator-=(mint& x, mint y) { return x = x.val-y.val+MODVAL; } 9f60383a2c 2012-06-16 kinaba: mint& operator*=(mint& x, mint y) { return x = LL(x.val)*y.val; } 9f60383a2c 2012-06-16 kinaba: mint POW(mint x, LL e) { mint v=1; for(;e;x*=x,e>>=1) if(e&1) v*=x; return v; } 9f60383a2c 2012-06-16 kinaba: mint& operator/=(mint& x, mint y) { return x *= POW(y, MODVAL-2); } 9f60383a2c 2012-06-16 kinaba: mint operator+(mint x, mint y) { return x+=y; } 9f60383a2c 2012-06-16 kinaba: mint operator-(mint x, mint y) { return x-=y; } 9f60383a2c 2012-06-16 kinaba: mint operator*(mint x, mint y) { return x*=y; } 9f60383a2c 2012-06-16 kinaba: mint operator/(mint x, mint y) { return x/=y; } 9f60383a2c 2012-06-16 kinaba: vector<mint> FAC_(1,1); 9f60383a2c 2012-06-16 kinaba: mint FAC(LL n) { while( FAC_.size()<=n ) FAC_.push_back( FAC_.back()*FAC_.size() ); return FAC_[n]; } 9f60383a2c 2012-06-16 kinaba: //mint C(LL n, LL k) { return k<0 || n<k ? 0 : FAC(n) / (FAC(k) * FAC(n-k)); } 9f60383a2c 2012-06-16 kinaba: 9f60383a2c 2012-06-16 kinaba: vector< vector<mint> > CP_; 9f60383a2c 2012-06-16 kinaba: mint C(LL n, LL k) { 9f60383a2c 2012-06-16 kinaba: while( CP_.size() <= n ) { 9f60383a2c 2012-06-16 kinaba: int nn = CP_.size(); 9f60383a2c 2012-06-16 kinaba: CP_.push_back(vector<mint>(nn+1,1)); 9f60383a2c 2012-06-16 kinaba: for(int kk=1; kk<nn; ++kk) 9f60383a2c 2012-06-16 kinaba: CP_[nn][kk] = CP_[nn-1][kk-1] + CP_[nn-1][kk]; 9f60383a2c 2012-06-16 kinaba: } 9f60383a2c 2012-06-16 kinaba: return k<0 || n<k ? 0 : CP_[n][k]; 9f60383a2c 2012-06-16 kinaba: } 9f60383a2c 2012-06-16 kinaba: 9f60383a2c 2012-06-16 kinaba: int gcd(int a, int b) { 9f60383a2c 2012-06-16 kinaba: while(a) 9f60383a2c 2012-06-16 kinaba: swap(a, b%=a); 9f60383a2c 2012-06-16 kinaba: return b; 9f60383a2c 2012-06-16 kinaba: } 9f60383a2c 2012-06-16 kinaba: 9f60383a2c 2012-06-16 kinaba: class Spacetsk { public: 9f60383a2c 2012-06-16 kinaba: int countsets(int L, int H, int K) 9f60383a2c 2012-06-16 kinaba: { 9f60383a2c 2012-06-16 kinaba: if( K==1 ) 9f60383a2c 2012-06-16 kinaba: return (L+1)*(H+1); 9f60383a2c 2012-06-16 kinaba: 9f60383a2c 2012-06-16 kinaba: mint sum = 0; 9f60383a2c 2012-06-16 kinaba: for(int x=0; x<=L; ++x) 9f60383a2c 2012-06-16 kinaba: for(int y=1; y<=H; ++y) 9f60383a2c 2012-06-16 kinaba: { 9f60383a2c 2012-06-16 kinaba: mint dup = (x==0 ? L+1 : 2*(L+1-x)); 9f60383a2c 2012-06-16 kinaba: mint mid = C(gcd(x, y), K-1); 9f60383a2c 2012-06-16 kinaba: sum = sum + dup*mid; 9f60383a2c 2012-06-16 kinaba: } 9f60383a2c 2012-06-16 kinaba: return sum.val; 9f60383a2c 2012-06-16 kinaba: } 9f60383a2c 2012-06-16 kinaba: }; 9f60383a2c 2012-06-16 kinaba: 9f60383a2c 2012-06-16 kinaba: // BEGIN CUT HERE 9f60383a2c 2012-06-16 kinaba: #include <ctime> 9f60383a2c 2012-06-16 kinaba: double start_time; string timer() 9f60383a2c 2012-06-16 kinaba: { ostringstream os; os << " (" << int((clock()-start_time)/CLOCKS_PER_SEC*1000) << " msec)"; return os.str(); } 9f60383a2c 2012-06-16 kinaba: template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) 9f60383a2c 2012-06-16 kinaba: { os << "{ "; 9f60383a2c 2012-06-16 kinaba: for(typename vector<T>::const_iterator it=v.begin(); it!=v.end(); ++it) 9f60383a2c 2012-06-16 kinaba: os << '\"' << *it << '\"' << (it+1==v.end() ? "" : ", "); os << " }"; return os; } 9f60383a2c 2012-06-16 kinaba: void verify_case(const int& Expected, const int& Received) { 9f60383a2c 2012-06-16 kinaba: bool ok = (Expected == Received); 9f60383a2c 2012-06-16 kinaba: if(ok) cerr << "PASSED" << timer() << endl; else { cerr << "FAILED" << timer() << endl; 9f60383a2c 2012-06-16 kinaba: cerr << "\to: \"" << Expected << '\"' << endl << "\tx: \"" << Received << '\"' << endl; } } 9f60383a2c 2012-06-16 kinaba: #define CASE(N) {cerr << "Test Case #" << N << "..." << flush; start_time=clock(); 9f60383a2c 2012-06-16 kinaba: #define END verify_case(_, Spacetsk().countsets(L, H, K));} 9f60383a2c 2012-06-16 kinaba: int main(){ 9f60383a2c 2012-06-16 kinaba: 9f60383a2c 2012-06-16 kinaba: CASE(0) 9f60383a2c 2012-06-16 kinaba: int L = 1; 9f60383a2c 2012-06-16 kinaba: int H = 1; 9f60383a2c 2012-06-16 kinaba: int K = 2; 9f60383a2c 2012-06-16 kinaba: int _ = 4; 9f60383a2c 2012-06-16 kinaba: END 9f60383a2c 2012-06-16 kinaba: CASE(1) 9f60383a2c 2012-06-16 kinaba: int L = 1; 9f60383a2c 2012-06-16 kinaba: int H = 1; 9f60383a2c 2012-06-16 kinaba: int K = 1; 9f60383a2c 2012-06-16 kinaba: int _ = 4; 9f60383a2c 2012-06-16 kinaba: END 9f60383a2c 2012-06-16 kinaba: CASE(2) 9f60383a2c 2012-06-16 kinaba: int L = 2; 9f60383a2c 2012-06-16 kinaba: int H = 2; 9f60383a2c 2012-06-16 kinaba: int K = 1; 9f60383a2c 2012-06-16 kinaba: int _ = 9; 9f60383a2c 2012-06-16 kinaba: END 9f60383a2c 2012-06-16 kinaba: CASE(3) 9f60383a2c 2012-06-16 kinaba: int L = 2; 9f60383a2c 2012-06-16 kinaba: int H = 2; 9f60383a2c 2012-06-16 kinaba: int K = 2; 9f60383a2c 2012-06-16 kinaba: int _ = 23; 9f60383a2c 2012-06-16 kinaba: END 9f60383a2c 2012-06-16 kinaba: CASE(4) 9f60383a2c 2012-06-16 kinaba: int L = 5; 9f60383a2c 2012-06-16 kinaba: int H = 5; 9f60383a2c 2012-06-16 kinaba: int K = 3; 9f60383a2c 2012-06-16 kinaba: int _ = 202; 9f60383a2c 2012-06-16 kinaba: END 9f60383a2c 2012-06-16 kinaba: CASE(5) 9f60383a2c 2012-06-16 kinaba: int L = 561; 9f60383a2c 2012-06-16 kinaba: int H = 394; 9f60383a2c 2012-06-16 kinaba: int K = 20; 9f60383a2c 2012-06-16 kinaba: int _ = 786097180; 9f60383a2c 2012-06-16 kinaba: END 9f60383a2c 2012-06-16 kinaba: CASE(6) 9f60383a2c 2012-06-16 kinaba: int L = 1; 9f60383a2c 2012-06-16 kinaba: int H = 1; 9f60383a2c 2012-06-16 kinaba: int K = 1; 9f60383a2c 2012-06-16 kinaba: int _ = 4; 9f60383a2c 2012-06-16 kinaba: END 9f60383a2c 2012-06-16 kinaba: CASE(7) 9f60383a2c 2012-06-16 kinaba: int L = 2000; 9f60383a2c 2012-06-16 kinaba: int H = 2000; 9f60383a2c 2012-06-16 kinaba: int K = 500; 9f60383a2c 2012-06-16 kinaba: int _ = -1; 9f60383a2c 2012-06-16 kinaba: END 9f60383a2c 2012-06-16 kinaba: CASE(7) 9f60383a2c 2012-06-16 kinaba: int L = 2000; 9f60383a2c 2012-06-16 kinaba: int H = 2000; 9f60383a2c 2012-06-16 kinaba: int K = 2; 9f60383a2c 2012-06-16 kinaba: int _ = -1; 9f60383a2c 2012-06-16 kinaba: END 9f60383a2c 2012-06-16 kinaba: } 9f60383a2c 2012-06-16 kinaba: // END CUT HERE