ForHosting KIT · Math

Pythagorean triple generator

Builds a Pythagorean triple from two whole numbers m greater than n with Euclid's formula: choosing 2 for m and 1 for n gives the 3-4-5 triangle. You also see whether the triple is primitive and a check that a² + b² = c². Free in your browser.

  • Free
  • Runs in your browser
  • No sign-up
  • Your data stays on your device
Use it from WebAPIEmailTelegramApp soon
If you enter
M
2
N
1
You get
A
3
B
4
C
5
Triple
3, 4, 5

Every integer solution to a squared plus b squared equals c squared can be built from a pair of positive integers m greater than n using Euclid’s classical parametrization. Teachers, contest programmers, and curriculum authors need those triples on demand without hand-multiplying squares or mixing up which leg is even. This Pythagorean triple generator accepts m and n, rejects non-positive values and any pair where m is not strictly larger than n, and returns the triple a equals m squared minus n squared, b equals two m n, and c equals m squared plus n squared, together with a primitivity flag and a verification check.

Euclid’s formula and what m and n mean

Euclid’s formula is the standard constructive generator for Pythagorean triples in elementary number theory. Given integers m and n with m strictly greater than n and both positive, set a equal to m squared minus n squared, b equal to twice the product m times n, and c equal to m squared plus n squared. A short expansion shows that a squared plus b squared equals c squared identically, so every valid pair yields a genuine right-triangle triple with integer sides.

The classic classroom seed is m equals two and n equals one, which produces the familiar three-four-five triangle: a equals three, b equals four, and c equals five. Raising m to three with n equal to two produces five-twelve-thirteen; m equals four and n equals one produces fifteen-eight-seventeen. When m and n are coprime and of opposite parity—one even and one odd—the resulting triple is primitive: the three sides share no common divisor greater than one.

If m and n share a factor, or both are odd, the triple is still valid but scaled: for example m equals three and n equals one both odd yields eight-six-ten, which is two times three-four-five. This capability always returns the raw Euclid triple for the parameters you supply; it does not rescale, swap legs, or search for a generator from a target hypotenuse. You choose m and n; it multiplies out a, b, and c and reports whether that triple is primitive under the standard criterion.

What to enter, what you get and what is refused

Both parameters must be strictly greater than zero; zero or negative values are rejected because Euclid’s formula is stated for positive generators. Additionally m must be strictly greater than n—if m equals n then a collapses to zero and the figure is not a triangle, and if m is smaller than n the usual ordered form of the formula is violated. Failed validation is not billed.

Example: m equals two and n equals one yields a equals three, b equals four, c equals five, primitive true. Example: m equals six and n equals three yields a equals twenty-seven, b equals thirty-six, c equals forty-five, primitive false because the generators share a factor of three.

Where a Pythagorean triple generator earns its keep

Classrooms and tutoring platforms use a Pythagorean triple generator so learners can explore families of right triangles without arithmetic slips on squares and products. Contest and olympiad trainers seed problems with primitive triples and need a deterministic oracle that marks invalid generator pairs instead of silently returning a degenerate zero-leg triple. Curriculum generators can walk m and n in nested loops, skip non-primitive pairs when desired, and collect hypotenuse lists for worksheets.

Invalid input does not consume balance. Keep m and n modest for classroom ranges, pin the expected triple arrays in tests, and you get reproducible integer sides for homework, LMS plugins, and edge workers without standing up a computer-algebra stack of your own.

Classroom exploration of right triangles

Let students pick m and n, see a, b, and c instantly, and discover when the triple is primitive versus a scaled multiple of a smaller one.

Contest problem seeding

Generate families of integer-sided right triangles for olympiad and programming-contest tasks with a deterministic Euclid oracle.

Game and curriculum tooling

Produce integer leg and hypotenuse lengths for tile maps, path design, or auto-generated worksheets without hand-maintained triple tables.

How does the Pythagorean triple generator work?

Send positive integers m and n with m > n.

What happens if m is not greater than n?

Euclid’s formula requires m > n > 0; equal or reversed parameters are rejected and not billed.

When is the triple primitive?

When gcd(m, n) = 1 and m and n have opposite parity (one even, one odd). Otherwise a, b, and c still form a valid triple but share a common factor.

Which m and n give the 5-12-13 triangle?

Use 3 for m and 2 for n. Then m² − n² is 5, 2mn is 12 and m² + n² is 13, and because 3 and 2 share no factor and one of them is even, the triple is primitive.

Why do 3 and 1 give the triple 8-6-10?

Both numbers are odd, so the formula produces a scaled triple: 8-6-10 is 3-4-5 doubled. It is still a valid right triangle, but it is not marked primitive.

Everything on this page is available programmatically. This section is for teams who want to wire it into their own systems; everyone else can just use the tool above.

POSThttps://api.kit.forhosting.com/numth/pythagorean-triple-generator

Prefer to automate it? One authenticated POST creates the task; the result comes back by webhook or a signed link. The same capability also runs here on the web, by email and from Telegram — and soon from our app too.

curl -X POST https://api.kit.forhosting.com/numth/pythagorean-triple-generator \
  -H "Authorization: Bearer $KIT_KEY" \
  -H "Content-Type: application/json" \
  -d '{"m":2,"n":1}'
{
  "m": 2,
  "n": 1
}
{
  "task_id": "tsk_a1b2c3d4e5f6a1b2c3d4e5f6",
  "type": "numth.pythagorean_triple_generator",
  "status": "queued",
  "_links": {
    "result": "/tasks/tsk_…/result"
  }
}

The API is asynchronous: the call returns a task_id immediately and the result arrives by webhook. Polling is capped at 1 req/s per task.

Per request$0.002

Published price — no tokens, no invented credits. A failed task is never charged.

HTTPCodeMeaning
401unauthorizedMissing or invalid API key.
402insufficient_balanceYour balance doesn't cover the task price.
404unknown_typeThat task type doesn't exist.
429rate_limitedToo many requests. Use the webhook instead of polling.

Input contract, response fields, and error behaviour

POST a JSON object with two required positive integers: m and n. Each field may arrive as a JSON number or as a digit-only string; empty strings, missing fields, non-integers, and non-finite values fail with invalid_input naming the field. On success the body echoes m and n, returns integer sides a, b, and c, includes a triple array in the order [a, b, c], a boolean primitive flag, a boolean check that a squared plus b squared equals c squared when those squares stay inside safe integer range, and a short formula string restating the identities. Safe-integer limits apply: m must not be so large that m squared leaves the IEEE-754 exact-integer range, and the computed a, b, and c themselves must remain safe integers. Pair the JSON with your own diagram code if you need a plotted right triangle; this endpoint only emits the numeric triple and metadata.

Where a Pythagorean triple generator earns its keep

Game and graphics authors sometimes need integer-sided right triangles for tile dimensions, path lengths, or level design constraints; calling a tiny parse API avoids embedding ad-hoc triple tables.

Is three-four-five included?

Yes. Use m = 2 and n = 1 to obtain a = 3, b = 4, c = 5 with primitive true—the fundamental primitive Pythagorean triple.

What does the Pythagorean triple generator cost?

The browser tool is free. API requests use prepaid KIT balance at $0.002 per successful call; invalid input is not billed.

Read the full KIT documentation →