2018-09-30 23:01:58 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								---
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								id: 5900f3b71000cf542c50feca
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								title: 'Problem 75: Singular integer right triangles'
							 
						 
					
						
							
								
									
										
										
										
											2020-11-27 19:02:05 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								challengeType: 5
							 
						 
					
						
							
								
									
										
										
										
											2019-08-05 09:17:33 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								forumTopicId: 302188
							 
						 
					
						
							
								
									
										
										
										
											2021-01-13 03:31:00 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								dashedName: problem-75-singular-integer-right-triangles
							 
						 
					
						
							
								
									
										
										
										
											2018-09-30 23:01:58 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								---
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2020-11-27 19:02:05 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								# --description--
  
						 
					
						
							
								
									
										
										
										
											2020-02-28 21:39:47 +09:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2018-09-30 23:01:58 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								It turns out that 12 cm is the smallest length of wire that can be bent to form an integer sided right angle triangle in exactly one way, but there are many more examples.
							 
						 
					
						
							
								
									
										
										
										
											2020-02-28 21:39:47 +09:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								< div  style = 'margin-left: 4em;' >  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  < strong > 12 cm:< / strong >  (3,4,5)< br > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  < strong > 24 cm:< / strong >  (6,8,10)< br > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  < strong > 30 cm:< / strong >  (5,12,13)< br > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  < strong > 36 cm:< / strong >  (9,12,15)< br > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  < strong > 40 cm:< / strong >  (8,15,17)< br > 
							 
						 
					
						
							
								
									
										
										
										
											2021-05-11 14:56:58 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								  < strong > 48 cm:< / strong >  (12,16,20)< br > < br > 
							 
						 
					
						
							
								
									
										
										
										
											2020-02-28 21:39:47 +09:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								< / div >  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2018-09-30 23:01:58 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								In contrast, some lengths of wire, like 20 cm, cannot be bent to form an integer sided right angle triangle, and other lengths allow more than one solution to be found; for example, using 120 cm it is possible to form exactly three different integer sided right angle triangles.
							 
						 
					
						
							
								
									
										
										
										
											2020-02-28 21:39:47 +09:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								< div  style = 'margin-left: 4em;' >  
						 
					
						
							
								
									
										
										
										
											2021-05-11 14:56:58 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								  < strong > 120 cm:< / strong >  (30,40,50), (20,48,52), (24,45,51)< br > < br > 
							 
						 
					
						
							
								
									
										
										
										
											2020-02-28 21:39:47 +09:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								< / div >  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2021-05-11 14:56:58 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								Given that L is the length of the wire, for how many values of L ≤ `n`  can exactly one, integer sided right angle, triangle be formed?
							 
						 
					
						
							
								
									
										
										
										
											2020-02-28 21:39:47 +09:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2020-11-27 19:02:05 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								# --hints--
  
						 
					
						
							
								
									
										
										
										
											2018-09-30 23:01:58 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2021-05-11 14:56:58 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								`singularIntRightTriangles(48)`  should return a number. 
						 
					
						
							
								
									
										
										
										
											2018-09-30 23:01:58 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2020-11-27 19:02:05 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								```js
							 
						 
					
						
							
								
									
										
										
										
											2021-05-11 14:56:58 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								assert(typeof singularIntRightTriangles(48) === 'number');
							 
						 
					
						
							
								
									
										
										
										
											2020-11-27 19:02:05 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								```
							 
						 
					
						
							
								
									
										
										
										
											2018-09-30 23:01:58 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2021-05-11 14:56:58 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								`singularIntRightTriangles(48)`  should return `6` . 
						 
					
						
							
								
									
										
										
										
											2018-09-30 23:01:58 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2020-11-27 19:02:05 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								```js
							 
						 
					
						
							
								
									
										
										
										
											2021-05-11 14:56:58 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								assert.strictEqual(singularIntRightTriangles(48), 6);
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								```
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								`singularIntRightTriangles(700000)`  should return `75783` . 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								```js
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								assert.strictEqual(singularIntRightTriangles(700000), 75783);
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								```
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								`singularIntRightTriangles(1000000)`  should return `107876` . 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								```js
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								assert.strictEqual(singularIntRightTriangles(1000000), 107876);
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								```
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								`singularIntRightTriangles(1500000)`  should return `161667` . 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								```js
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								assert.strictEqual(singularIntRightTriangles(1500000), 161667);
							 
						 
					
						
							
								
									
										
										
										
											2018-09-30 23:01:58 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								```
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2020-11-27 19:02:05 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								# --seed--
  
						 
					
						
							
								
									
										
										
										
											2018-09-30 23:01:58 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2020-11-27 19:02:05 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								## --seed-contents--
  
						 
					
						
							
								
									
										
										
										
											2018-09-30 23:01:58 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								```js
							 
						 
					
						
							
								
									
										
										
										
											2021-05-11 14:56:58 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								function singularIntRightTriangles(n) {
							 
						 
					
						
							
								
									
										
										
										
											2020-09-15 09:57:40 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2018-09-30 23:01:58 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								  return true;
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2021-05-11 14:56:58 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								singularIntRightTriangles(48);
							 
						 
					
						
							
								
									
										
										
										
											2018-09-30 23:01:58 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								```
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2020-11-27 19:02:05 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								# --solutions--
  
						 
					
						
							
								
									
										
										
										
											2018-09-30 23:01:58 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								```js
							 
						 
					
						
							
								
									
										
										
										
											2021-05-11 14:56:58 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								function singularIntRightTriangles(limit) {
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  function euclidFormula(m, n) {
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    return [m **  2 - n **  2, 2 * m *  n, m **  2 + n **  2];
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  function gcd(numberA, numberB) {
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    if (numberB === 0) {
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      return numberA;
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    return gcd(numberB, numberA % numberB);
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  function notBothOdd(numberA, numberB) {
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    return (numberA + numberB) % 2 === 1;
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  function areCoprime(numberA, numberB) {
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    return gcd(numberA, numberB) === 1;
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  const trianglesWithPerimeter = new Array(limit + 1).fill(0);
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  const mLimit = Math.sqrt(limit / 2);
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  for (let m = 2; m <  mLimit ;  m + + )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    for (let n = 1; n <  m ;  n + + )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      if (notBothOdd(m, n) & &  areCoprime(m, n)) {
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        const [sideA, sideB, sideC] = euclidFormula(m, n);
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        const perimeter = sideA + sideB + sideC;
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        let curPerimeter = perimeter;
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        while (curPerimeter < = limit) {
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								          trianglesWithPerimeter[curPerimeter]++;
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								          curPerimeter += perimeter;
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  return trianglesWithPerimeter.filter(trianglesCount => trianglesCount === 1)
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    .length;
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}
							 
						 
					
						
							
								
									
										
										
										
											2018-09-30 23:01:58 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								```