CP4CPPF(S,T): counting in 1D, 2D, 3D, 4D and ND | CP4CPP⇩

The original Codeforces problem asks for ordered nonnegative triples satisfying a sum bound and a product bound, with inputs up to 101810^{18}. Its dimension-dd form is

Fd(S,T)=#{x∈Z≥0d:∑ixi≤S,∏ixi≤T}.F_d(S,T)=\#\left\{\mathbf x\in\mathbb Z_{\ge0}^{d}: \sum_i x_i\le S,\quad\prod_i x_i\le T\right\}.

Both inequalities include equality. Coordinates are ordered: (1,2,3)(1,2,3) and (3,2,1)(3,2,1) count separately. Throughout, S,TS,T are nonnegative integers and (nk)=0\binom nk=0 for n<kn<k.

[O] shows each dimension; [E] contains five bounded C++17 references; [I] tests the same counts. These examples explain exact arithmetic. They do not implement the fast thesis algorithms.

One coordinate is both the sum and the product:

0≤x≤min⁡(S,T)⟹F1(S,T)=1+min⁡(S,T).0\le x\le\min(S,T) \quad\Longrightarrow\quad \boxed{F_1(S,T)=1+\min(S,T)}.

For S=6,T=3S=6,T=3, the integers are 0,1,2,30,1,2,3: four points. Counting the interval takes constant many arithmetic operations. Binary input/output still costs time proportional to its length.

Experiment: 1D: intersect the integer bounds