how can you get the answer like this? Does the right-angled edge have to be an integer?
-update
there is no big problem with your program, so it belongs to the common solution. If you want to optimize, you can consider it from two aspects:
if you only need to find one answer, you can jump out of the loop in time after finding it.
when a has been determined, there is at most one solution, and the inner loop can be accelerated by dichotomy.
the answer to this question should be like this. Let me tell you the train of thought
first of all, it only takes one loop to get the answer to this question
because it is known that the radius of the inner circle and the triangle are right angles, is it determined if one of the right sides is X and the other is the length of the other?
and then think about the scope of this cycle, because the length of the inscribed circle is 2r, so X is at least when the 2r+1 loop ends
.
when X slowly becomes longer, the triangle will slowly approach the isosceles triangle and the side length is D, just cycle X < = D,
then it is proved that, because there is an integer X1 in X > D, so that the other right-angled edge is also an integer X2, then X2 must be less than D,
.
because when the triangle is an isosceles right triangle, the other right side is D, X and the other edge will slowly become shorter
.
so this X1Magol X2 solution will be found in X=X2
The
idea of
is actually very simple after having the code. The main workload is to calculate the other edge according to X, which lists an equation on a piece of paper and writes it in
.
I write a pseudo code. The edge of an isosceles right triangle with a radius of r inner tangent circle is 2r + square 2r
.
for(int x = 2*r+1 ; x <= 2r+2r ; xPP){
x2 = f(x,r) //
if(x2 ){
printf("%d %d",x,x2)
}
}
if not, it means there is no solution