Number of Integer sided triangles

82 Views Asked by At

Are there any formula or something finding no of integer sided triangle with sides from first "n" natural numbers? I know that sum and difference of side of triangle rule.But how can we put that in action for this problem or are there any other way to solve.

1

There are 1 best solutions below

0
On

You want to find all $(a,b,c)$ with $n\ge a\ge b\ge c\ge 1$. First, do a bit of stupid brute-force programming to get an idea:

for n in range(1, 100):
  cnt = 0
  for a in range(1, n + 1):
    for b in range(1, a + 1):
      for c in range(1, b + 1):
        if b + c > a:
          cnt += 1
  print("n={} cnt={}".format(n, cnt))

Let this run, feed the results into OEIS and you find http://oeis.org/A002623 which has a comment

Also number of nondegenerate triangles that can be made from rods of length 1,2,3,4,...,n. - Alfred Bruckstein

and also some formulas, e.g. the one from Jerry Lewis:

$$a(n) = \frac{\frac{(2n+3)(n+2)(n+1)}6-\left\lfloor\frac{n+2}2\right\rfloor}4$$