@subarna_08.
Correct summation is : ((B/2) - 1) + ((B/2) - 2) + … + 1 = Sum of first ((B/2) - 1) positive integers.
Hence the correct answer is: ( ((B/2) - 1)(B/2) )/2.
(Sum of first n positive integers is n(n+1)/2)
“we will have (B/2−1) squares in the base, and we will be left with another isosceles right angle triangle having base length (B−2).”
Where does this thing come from… please help me …
Hey!. Let the base length is B. Since the triangle is right-angled isosceles, even the perpendicular is B. The angle between base and hypotenuse is 45 degrees.(tan theta = B/B = 1). Now we need to find the position on the base beyond which a square of 2 units cannot exist. Again from tan theta, this is 2. Therefore, squares can be drawn on B-2 space. Therefore number of squares = (B-2)/2 = B/2 - 1. These squares are on the base. The part left in perpendicular is B-2, which is again a right-angled isosceles triangle. Hope this helps!
If n=10**4 (see constraints) then it will raise recursion error hence it is better to use mathematical approach than recursion one. Hope this helps. Happy coding!
This solution is for a square of nxn.
Triangle base is B.
int main(){
int t, B; //no. of testcase and base of a triangle
int k, n;
cin>>t;
while (t–){
int result;
cin>>B;
k = B/n;
result = (k*(k-1))/2;
cout<<result<<endl;
}
}