Counting
Lesson 17 of 20 in Coddy's Mathematical Riddles course.
A Pythagorean triplet {a, b, c} forms right angle triangle.
Let p be the perimeter of a right angle triangle with integer length sides, {a, b, c}.
There is exactly one triplet for p=12: {3,4,5}, p=24: {6,8,10} and for p=30: {5,12,13}.
There are exactly three triplets for p = 120: {20,48,52}, {24,45,51}, {30,40,50}.
In contrast, there are no triplet for p=20.
For p≤120, there is one p with three triplets (p=120), three p with two triplets (p=60,84,90), and exactly 13 p with just one triplet.
Challenge
HardHow many p≤1000 with just one triplet?
Write a function count1PythagoreanTripletSolution that get an integer N, and return the number of integers p≤N that only one integer Pythagorean triplet.
Try it yourself
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>
#include "solution.h"
int main() {
int n;
if (scanf("%d", &n) != 1) n = 0;
int r = count1PythagoreanTripletSolution(n);
printf("%d\n", r);
return 0;
}