### Statement
[This problem](https://codeforces.com/blog/entry/93981)
Given S,T(0≤S,T≤1018)
I need to count the number of tuple (a,b,c) satisfied (min(a,b,c)≥0) and (a+b+c≤S) and (a×b×c≤T)
I tried to fix a to be the minimum and (0≤a≤3T) then count the number of pair (b,c) satisfied (min(b,c)≥a) and (b+c≤S−a) and (b×c≤⌊aT⌋).
------------------------------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------------------------------
### Combinatorics Approach
Because some tuple (a,b,c) may equal to (a,c,b),(b,a,c),(b,c,a),(c,a,b) or (c,b,a) (example a=b), while some may not (example a<b<c). Therefore I split into 4 cases
>>>>>>>>>>>>>>>>>>>>> Case**[1]** ⇒ 0≤a<b<c and (a≤3T)
cnt1=a=0∑0b=1∑Sc=b+1∑S−bI(1)+a=1∑min(S,⌊3T⌋)b=a+1∑min(S−a,⌊aT⌋)c=b+1∑min(S−a−b,⌊abT⌋)I(1)
=b=1∑Smax(0,S−2b)+a=1∑min(S,⌊3T⌋)b=a+1∑min(S−a,aT)max(0,min(S−a−b,⌊abT⌋)−b)
=⌊2S⌋×S−2×x=1∑⌊2S⌋I(x)+a=1∑min(S,⌊3T⌋)( x=1∑f(a)I(x)+(S−a)(g(a)−a)−x=a+1∑g(a)I(x)+x=g(a)+1∑f(a)⌊xaT⌋)
for I(x)=x
for f(a)=⌊min(2S−a2aT+1,⌊aT⌋)⌋
and g(a)=max(k ∣ S−a−k≤⌊aT⌋)
>>>>>>>>>>>>>>>>>>>>> Case**[2]** ⇒ 0≤a<b=c and (a≤3T)
cnt2=a=0∑0b=1∑⌊2S⌋c=b∑bI(1)+a=1∑min(S,⌊3T⌋)b=1∑min(2S−a,⌊aT⌋)c=b∑bI(1)
=⌊2S⌋+a=1∑min(S,⌊3T⌋)max(0,⌊min(2S−a,⌊aT⌋)⌋−a)
>>>>>>>>>>>>>>>>>>>>> Case**[3]** ⇒ 0≤a=b<c and (a≤3T)
cnt3=a=0∑0b=a∑ac=1∑SI(1)+a=1∑min(⌊2S⌋,⌊3T⌋)b=a∑ac=b+1∑min(S−a−b,⌊abT⌋)I(1)
=S+a=1∑min(⌊2S⌋,⌊3T⌋)max(0,min(S−2a,⌊a2T⌋)−a)
>>>>>>>>>>>>>>>>>>>>> Case**[4]** ⇒ 0≤a=b=c and (a≤3T)
cnt4=a=0∑min(3S,3T)b=a∑ac=b∑bI(1)
=⌊min(3S,3T)⌋+1
>>>>>>>>>>>>>>>>>>>>> Now result = number of different tuple (a,b,c) satisfied the condition
In case **[1]** (a,b,c)=(a,c,b)=(b,a,c)=(b,c,a)=(c,a,b)=(c,b,a)
In case **[2]** (a,b,c)=(b,c,a)=(c,a,b)
In case **[3]** (a,b,c)=(b,c,a)=(c,a,b)
In case **[4]** (a,b,c) is unique
Therefore, result=6×cnt1+3×cnt2+3×cnt3+1×cnt4
------------------------------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------------------------------
### Algorithm Complexity
It is known that x=lΣr(x)=2r(r+1)−2l(l−1) when l≤r and x=lΣr(x)=0 otherwise
Let f(p,q,x)=k=1Σmin(q,⌊xT⌋)⌊xkT⌋
> There is O(T) solution based on the fact that the number of different floor value in that series is O(T)
> There is also a O(3Tlog(T)) solution based on the fact that the number of different slopes in from the graph of that series is O(3T)
The overall complexity should be O(T31×a=1Σmin(S,⌊3T⌋)2⌊2⌊aT⌋⌋)≈O(T21)
or even be O(T31×a=1Σmin(S,⌊3T⌋)3⌊2⌊aT⌋⌋)≈O(T21)
But for some reasons or maybe hidden constant it seems to be about O(T32)
It is also known that by not fixing a as minimum, you can also achieve O(S×3T)
------------------------------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------------------------------
### My Question:
> Any of this question if it is solvable then the whole problem is solvable for O(3T) !
- Is there an alternative formula which can run in O(2(T)) or even O(3(T)) ?
- Is there a faster algorithm to calculate f(p,q,x) ?
- Is there a formula to calculate f(p,q,x) from f(p,q,x−1) or even from f(l,r,x−1) for some (l,r)
- Can I calculate f(p,q,x) from f(l,r,x−1) for some (l,r) faster than O(log(T)) ?
- Given a array p[] of T numbers where p[i]=⌊iT⌋. Given O(3T) queries Q(l,r,x)=x=lΣrp[x]. Can this be solved in O(3T) after somehow compressing p[] and optimizing the calculation ?
[This problem](https://codeforces.com/blog/entry/93981)
Given S,T(0≤S,T≤1018)
I need to count the number of tuple (a,b,c) satisfied (min(a,b,c)≥0) and (a+b+c≤S) and (a×b×c≤T)
I tried to fix a to be the minimum and (0≤a≤3T) then count the number of pair (b,c) satisfied (min(b,c)≥a) and (b+c≤S−a) and (b×c≤⌊aT⌋).
------------------------------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------------------------------
### Combinatorics Approach
Because some tuple (a,b,c) may equal to (a,c,b),(b,a,c),(b,c,a),(c,a,b) or (c,b,a) (example a=b), while some may not (example a<b<c). Therefore I split into 4 cases
>>>>>>>>>>>>>>>>>>>>> Case**[1]** ⇒ 0≤a<b<c and (a≤3T)
cnt1=a=0∑0b=1∑Sc=b+1∑S−bI(1)+a=1∑min(S,⌊3T⌋)b=a+1∑min(S−a,⌊aT⌋)c=b+1∑min(S−a−b,⌊abT⌋)I(1)
=b=1∑Smax(0,S−2b)+a=1∑min(S,⌊3T⌋)b=a+1∑min(S−a,aT)max(0,min(S−a−b,⌊abT⌋)−b)
=⌊2S⌋×S−2×x=1∑⌊2S⌋I(x)+a=1∑min(S,⌊3T⌋)( x=1∑f(a)I(x)+(S−a)(g(a)−a)−x=a+1∑g(a)I(x)+x=g(a)+1∑f(a)⌊xaT⌋)
for I(x)=x
for f(a)=⌊min(2S−a2aT+1,⌊aT⌋)⌋
and g(a)=max(k ∣ S−a−k≤⌊aT⌋)
>>>>>>>>>>>>>>>>>>>>> Case**[2]** ⇒ 0≤a<b=c and (a≤3T)
cnt2=a=0∑0b=1∑⌊2S⌋c=b∑bI(1)+a=1∑min(S,⌊3T⌋)b=1∑min(2S−a,⌊aT⌋)c=b∑bI(1)
=⌊2S⌋+a=1∑min(S,⌊3T⌋)max(0,⌊min(2S−a,⌊aT⌋)⌋−a)
>>>>>>>>>>>>>>>>>>>>> Case**[3]** ⇒ 0≤a=b<c and (a≤3T)
cnt3=a=0∑0b=a∑ac=1∑SI(1)+a=1∑min(⌊2S⌋,⌊3T⌋)b=a∑ac=b+1∑min(S−a−b,⌊abT⌋)I(1)
=S+a=1∑min(⌊2S⌋,⌊3T⌋)max(0,min(S−2a,⌊a2T⌋)−a)
>>>>>>>>>>>>>>>>>>>>> Case**[4]** ⇒ 0≤a=b=c and (a≤3T)
cnt4=a=0∑min(3S,3T)b=a∑ac=b∑bI(1)
=⌊min(3S,3T)⌋+1
>>>>>>>>>>>>>>>>>>>>> Now result = number of different tuple (a,b,c) satisfied the condition
In case **[1]** (a,b,c)=(a,c,b)=(b,a,c)=(b,c,a)=(c,a,b)=(c,b,a)
In case **[2]** (a,b,c)=(b,c,a)=(c,a,b)
In case **[3]** (a,b,c)=(b,c,a)=(c,a,b)
In case **[4]** (a,b,c) is unique
Therefore, result=6×cnt1+3×cnt2+3×cnt3+1×cnt4
------------------------------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------------------------------
### Algorithm Complexity
It is known that x=lΣr(x)=2r(r+1)−2l(l−1) when l≤r and x=lΣr(x)=0 otherwise
Let f(p,q,x)=k=1Σmin(q,⌊xT⌋)⌊xkT⌋
> There is O(T) solution based on the fact that the number of different floor value in that series is O(T)
> There is also a O(3Tlog(T)) solution based on the fact that the number of different slopes in from the graph of that series is O(3T)
The overall complexity should be O(T31×a=1Σmin(S,⌊3T⌋)2⌊2⌊aT⌋⌋)≈O(T21)
or even be O(T31×a=1Σmin(S,⌊3T⌋)3⌊2⌊aT⌋⌋)≈O(T21)
But for some reasons or maybe hidden constant it seems to be about O(T32)
It is also known that by not fixing a as minimum, you can also achieve O(S×3T)
------------------------------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------------------------------
### My Question:
> Any of this question if it is solvable then the whole problem is solvable for O(3T) !
- Is there an alternative formula which can run in O(2(T)) or even O(3(T)) ?
- Is there a faster algorithm to calculate f(p,q,x) ?
- Is there a formula to calculate f(p,q,x) from f(p,q,x−1) or even from f(l,r,x−1) for some (l,r)
- Can I calculate f(p,q,x) from f(l,r,x−1) for some (l,r) faster than O(log(T)) ?
- Given a array p[] of T numbers where p[i]=⌊iT⌋. Given O(3T) queries Q(l,r,x)=x=lΣrp[x]. Can this be solved in O(3T) after somehow compressing p[] and optimizing the calculation ?