For people willing to know where this statement came from:
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).
You can deduce this simply by using simple trigonometry. I was also curious to find the reason behind this and then got to this approach. Please correct me if I’m wrong or if there’s a better approach. If you can, try visualizing this on a notebook.
Consider in triangle XYZ, YZ is the base with Z as the right-angled vertex. Thus, YX is the hypotenuse. Let the length of base YZ = B. SInce, it’s an isosceles triangle length of YX is also B. Thus, the angle XYZ is 45 degrees (tan(XYZ) = B/B = 1). If we start filling squares of side 2 units from vertex Z, we can only fill them until the distance between base and the hypotenuse becomes less than 2. Since, the corresponding angle is 45 degrees, the distance from Y to this point will also be 2. Hence, we will not be able to place 1 square of side 2 here. The total number of squares that could be filled thus B/2 - 1. B/2 since there are of side 2 units. Then we are left with another isosceles triangle above these filled squares with base B-2 that is simply the sum of the length of upper sides of all squares (2*(B/2 - 1) = B - 2).
@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;
}
}