Artifact 89efd56699a58e1af39bcb25e02a6c6852788eed
#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>
#include <cstring>
#ifdef __GNUC__
#include <ext/hash_map>
#define unordered_map __gnu_cxx::hash_map
#else
#include <unordered_map>
#endif
using namespace std;
typedef long long LL;
typedef complex<double> CMP;
class BigAndSmallAirports { public:
long long solve(int Nlo, int Nhi, int Blo, int Bhi, int Slo, int Shi)
{
LL cnt = 0;
for(int B=Blo; B<=Bhi; ++B)
for(int S=Slo; S<=Shi; ++S)
if( S < B )
cnt += fast(Nhi, B, S) - fast(Nlo-1, B, S);
return cnt;
}
LL fast(LL N, LL B, LL S)
{
LL cnt = 0;
for(LL k=0; k<=N; ++k) {
LL Nmin = ((1+B+S)*k - k*k + S-1) / S;
if( Nmin < 0 ) {
cnt += (N-k+1)*(N-k+2)/2;
break;
}
Nmin = max(Nmin, k);
if( N >= Nmin )
cnt += (N-Nmin+1);
}
return cnt;
}
};
// 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 long long& Expected, const long long& 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(_, BigAndSmallAirports().solve(Nlo, Nhi, Blo, Bhi, Slo, Shi));}
int main(){
CASE(0)
int Nlo = 20;
int Nhi = 20;
int Blo = 3;
int Bhi = 3;
int Slo = 2;
int Shi = 2;
long long _ = 21LL;
END
CASE(1)
int Nlo = 1;
int Nhi = 1;
int Blo = 10;
int Bhi = 10;
int Slo = 2;
int Shi = 2;
long long _ = 1LL;
END
CASE(2)
int Nlo = 10;
int Nhi = 10;
int Blo = 8;
int Bhi = 8;
int Slo = 3;
int Shi = 3;
long long _ = 6LL;
END
CASE(3)
int Nlo = 10;
int Nhi = 100;
int Blo = 13;
int Bhi = 15;
int Slo = 18;
int Shi = 22;
long long _ = 0LL;
END
CASE(4)
int Nlo = 30;
int Nhi = 32;
int Blo = 8;
int Bhi = 10;
int Slo = 6;
int Shi = 8;
long long _ = 768LL;
END
CASE(5)
int Nlo = 1;
int Nhi = 10000000;
int Blo = 1;
int Bhi = 200;
int Slo = 1;
int Shi = 200;
long long _ = -1LL;
END
/*
CASE(6)
int Nlo = ;
int Nhi = ;
int Blo = ;
int Bhi = ;
int Slo = ;
int Shi = ;
long long _ = LL;
END
*/
}
// END CUT HERE