NTLib - Number Theory Library 0.9
Loading...
Searching...
No Matches
pythagorean_triple Module Reference

Generate primitive Pythagorean triples. More...

Functions

template<Integer T>
constexpr std::vector< std::tuple< T, T, T > > ntlib::primitive_pythagorean_triples (T N)
 Creates all primitive pythagorean triples \((a,b,c)\) with \(a \leq b \leq c \leq N\).

Detailed Description

Generate primitive Pythagorean triples.

Implementations to generate Pythagorean triples, i.e., triples \((a,b,c)\) such that \(a^2 + b^2 = c^2\). A triple is called primitive, if \(\mathrm{gcd}(a,b,c) = 1\).

For all integers \(u > v > 1\) we get a Pythagorean triple by setting

\[\begin{align} a &\colon= u^2 - v^2 \\ b &\colon= 2uv \\ c &\colon= u^2 + v^2` \end{align} \]

The smalles primitive triple is \((3,4,5)\), obtained by choosing \(u = 2\) and \(v = 1\).

It holds that \((a,b,c)\) is primitive, if and only if \(\mathrm{gcd}(u,v) = 1\) and at least one of them is even. Every primitive Pythagorean triple an be constructed by above formula.

Files

file  modules/combinatorics/pythagorean_triple.cpp
 Primary module interface unit for module pythagorean_triple.