Relatively prime checker
8 and 15 are relatively prime because their only common divisor is 1, even though neither number is prime. Enter two integers and get their greatest common divisor plus a clear yes or no. Signs are ignored. Free in your browser.
- Free
- Runs in your browser
- No sign-up
- Your data stays on your device
Run — free
Worked example
- A
- 8
- B
- 15
- Gcd
- 1
Two integers are relatively prime when they share no common factor greater than one. Equivalently, their greatest common divisor is exactly one. Use it when a worksheet, a fraction in lowest terms, or a modular inverse precondition asks whether two integers are relatively prime.
What relatively prime means and how the gcd decides it
Two integers are relatively prime, also called coprime in later number-theory texts, when their only positive common divisor is one. That is the same statement as gcd of a and b equals one. Eight and fifteen are the classroom example: the positive divisors of eight are one, two, four, and eight; the positive divisors of fifteen are one, three, five, and fifteen; the lists meet only at one, so the pair is relatively prime.
Fourteen and twenty-one are the contrasting example: both are divisible by seven, so they are not relatively prime even though neither number is prime. The identity used here is elementary and exact. Take the absolute values so that signs never change the answer, feed those non-negative integers to the Euclidean algorithm, and read the last non-zero remainder as the greatest common divisor.
Zero and five is a valid pair whose gcd is five, so the flag is false. Zero and one is a valid pair whose gcd is one, so the flag is true. Zero and zero is rejected because gcd of zero and zero is undefined in this contract and relative primality cannot be decided.
This landing answers the search for a relatively prime checker; it does not factor a single integer into primes and it does not reduce a ratio a colon b, which are neighbouring questions with their own pages.
What you can do with it
Lowest-terms fraction checks
Confirm that a numerator and a denominator share no common factor greater than one before accepting a fraction as already reduced.
Modular inverse preconditions
Verify that a coefficient and a modulus are relatively prime so an inverse is guaranteed to exist in modular-arithmetic demos and contest solutions.
FAQ
When are two integers relatively prime?
When they share no common factor greater than one, which is the same as gcd(|a|,|b|) equaling one.
What happens if either input is not an integer?
Fractions, scientific notation, empty strings, and non-numeric values are rejected and are not billed.
Are 14 and 21 relatively prime?
No. Both are divisible by 7, so their greatest common divisor is 7, not 1. What decides the answer is whether the pair shares a factor, not whether each number is prime.
Do negative numbers work?
Yes. The signs are dropped before the greatest common divisor is found, so −8 and 15 give the same answer as 8 and 15: they are still relatively prime.
What if one of the two numbers is zero?
Zero is accepted as long as the other number is not zero. 0 and 1 are relatively prime, while 0 and 5 are not, since their greatest common divisor is 5. Two zeros are rejected.
Related tools
For developers — API access
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.
API endpoint
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.
Call it from your stack
curl -X POST https://api.kit.forhosting.com/math/relatively-prime \
-H "Authorization: Bearer $KIT_KEY" \
-H "Content-Type: application/json" \
-d '{"a":8,"b":15}'const res = await fetch("https://api.kit.forhosting.com/math/relatively-prime", {
method: "POST",
headers: {
"Authorization": `Bearer ${process.env.KIT_KEY}`,
"Content-Type": "application/json"
},
body: JSON.stringify({
"a": 8,
"b": 15
})
});
const { task_id } = await res.json();import os, requests
res = requests.post(
"https://api.kit.forhosting.com/math/relatively-prime",
headers={"Authorization": f"Bearer {os.environ['KIT_KEY']}"},
json={
"a": 8,
"b": 15
},
)
task_id = res.json()["task_id"]<?php
$res = file_get_contents("https://api.kit.forhosting.com/math/relatively-prime", false, stream_context_create([
"http" => [
"method" => "POST",
"header" => "Authorization: Bearer " . getenv("KIT_KEY") . "\r\nContent-Type: application/json",
"content" => '{"a":8,"b":15}',
],
]));
$task = json_decode($res, true);body := bytes.NewBufferString(`{"a":8,"b":15}`)
req, _ := http.NewRequest("POST", "https://api.kit.forhosting.com/math/relatively-prime", body)
req.Header.Set("Authorization", "Bearer "+os.Getenv("KIT_KEY"))
req.Header.Set("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)Example request
{
"a": 8,
"b": 15
}Example response
{
"task_id": "tsk_a1b2c3d4e5f6a1b2c3d4e5f6",
"type": "math.relatively_prime",
"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.
Pricing
Published price — no tokens, no invented credits. A failed task is never charged.
Limits
max_abs | 9007199254740991 |
Errors
| HTTP | Code | Meaning |
|---|---|---|
401 | unauthorized | Missing or invalid API key. |
402 | insufficient_balance | Your balance doesn't cover the task price. |
404 | unknown_type | That task type doesn't exist. |
429 | rate_limited | Too many requests. Use the webhook instead of polling. |
Technical notes
This checker accepts a pair of integers, runs the Euclidean algorithm on their absolute values, and returns the positive gcd together with a boolean that is true only when that gcd equals one. Non-integers and the undefined pair zero with zero fail with invalid_input and are not billed. A successful API request costs $0.002.
What relatively prime means and how the gcd decides it
The boolean relatively_prime is true if and only if that remainder is one.
Input contract, response shape, and integer validation
Negative inputs are allowed and are reduced through absolute values, matching the usual convention that gcd is non-negative: negative eight and fifteen are still relatively prime. Send a JSON body with two required integers named a and b. Each field may arrive as a JSON integer or as a whole decimal string with an optional leading plus or minus sign. The aliases first and x are accepted for a; second and y are accepted for b, so forms, spreadsheets, and query strings can reuse one contract. Missing fields, empty strings, fractions, embedded spaces, scientific notation, infinities, and values outside the safe integer range fail with invalid_input and name the offending field. Those failures are not billed. On success the body echoes the parsed integers a and b, reports gcd as a non-negative integer, sets relatively_prime true exactly when that gcd equals one, and includes a short formula string restating the identity gcd of the absolute values equals one. A successful API request is charged the published $0.002 base price with unit item.
Where a relatively prime check earns its keep
Students meet relatively prime pairs when a fraction is already in lowest terms, when a modular inverse exists because the coefficient and the modulus share no factor greater than one, and when a worksheet asks whether two given integers are relatively prime. Teachers can generate answer keys without trusting an opaque calculator that hides the gcd. Contest practice often needs a fast offline source of gcd and relatively-prime answers so solutions can be checked without downloading tables. Pair classroom examples deliberately: eight and fifteen produce gcd one and relatively_prime true; twenty-one and thirty-five produce gcd seven and relatively_prime false; three point five and nine demonstrates the invalid_input path for a non-integer. Failed tasks that return invalid_input do not consume prepaid balance. Pin the gcd and the boolean in tests. This page targets people searching for a relatively prime calculator, are two numbers relatively prime, or gcd equals one checker; it is not a prime-factorization tool and not a ratio simplifier. API pricing remains the flat $0.002 per successful request.
Integration use cases
Deterministic test fixtures
Generate reproducible relatively-prime and non-relatively-prime pairs for unit tests, property checks, and CI assertions without embedding static tables.
Technical questions
Are negative integers allowed?
Yes. Signs are accepted and the gcd is computed on absolute values, so gcd is always a non-negative integer and relatively_prime depends only on that value.
What happens if both a and b are zero?
The request fails with invalid_input. gcd(0,0) is undefined here and relative primality cannot be decided when both inputs are zero.
What does the relatively prime checker cost?
The browser tool is free. API requests use prepaid KIT balance at $0.002 per successful call; invalid input is not billed.