1

I am trying to solve the HackerRank version.

The problem statement,

Let us call an integer sided triangle with sides a ≤ b ≤ c barely obtuse if the sides satisfy $a^2 + b^2 = c^2 - 1$.

How many barely obtuse triangles are there with perimeter ≤ $75,000,000$

So the solution that I thought should work is finding the general solution for the above equation, and trying to check the numbers which satisfies all of them.

So this would be $O(n)$ in terms of time efficiency.

The solutions I found are: $a = 2m$, $b = 2m^2$ and $c = 2m^2 + 1$.

Where $ m \ge 1.$

This solution gives correct output for perimeter 21, which should give two triplets $(2,2,3)$ and $(4,8,9)$

But for $75,000,000$ it gives 4329 counts, which is very less than expected.

So now I am not able to understand why some numbers which should be solution are being excluded from this?

I also tried another general solution $a = 2m$, $b = \sqrt{2m}$ and $c = (m+1)$, but it also is giving same outputs as the above one.

I am not able to understand which specific solutions are being skipped in both solutions?

  • Even for $1\le a\le b\le 10^5$ there are more than $4329$ solutions to $a^2+b^2+1=c^2$ (I did not search them all) and the perimeter is far smaller than $75\cdot 10^6$. – Peter Jan 24 '19 at 08:48
  • @Peter Yes, I totally agree. But the issue is that which numbers are getting missed in this general solution that I have found? – PradyumanDixit Jan 24 '19 at 09:21

2 Answers2

1

For $a = 2m, b=2m^2$ and $c = 2m^2 + 1$, you are missing a lot of solutions since $c$ is not always $b + 1$. Ex: $a = 4, b = 8, c = 9$

For the second one, $a = 2m, b = \sqrt{2m}$ and $c = m + 1$, $$ a^2 + b^2 = c^2 - 1$$ $$4m^2 + 2m = m^2 + 2m + 1$$ $$3m^2 = 1$$ $$m = \pm \frac{1}{\sqrt{3}}$$ This is not a general solution for the problem.

0

Another possible parametrization is $$a=6x^2+4x+2$$ $$b=8x^2+2x+2$$ $$c=10x^2+4x+3$$ giving infinite many solutions which are not of the type you mentioned. Not sure whether we get all solutions , if we add them to your list.

Peter
  • 86,576
  • Yes, But can you tell why am I missing some numbers, when I am trying a general solution for the equation and looping the integer m from the lowest to highest possible limit. Why am I missing some numbers? – PradyumanDixit Jan 25 '19 at 04:42