Linear combination of two numbers
Find whole numbers to multiply 15 and 25 by so the sum is 10: 15 × 4 + 25 × (−2) = 10, possible because their greatest common divisor, 5, divides 10. When it does not, you are told no solution exists. Free in your browser.
- Free
- Runs in your browser
- No sign-up
- Your data stays on your device
Run — free
Worked example
- A
- 15
- B
- 25
- C
- 10
- Gcd
- 5
- X
- 4
- Y
- -2
- Check
- 10
A linear combination of two integers a and b is any integer that can be written as a times x plus b times y for some integers x and y. Not every target is reachable: Bézout’s theorem says the reachable set is exactly the multiples of the greatest common divisor of a and b. This linear combination of two numbers calculator accepts coefficients a and b plus a target c, computes that gcd with the extended Euclidean algorithm, and either returns a particular pair of coefficients that realises the target or reports that no integer solution exists. Students use it to check Diophantine homework; developers use the same pure contract in contests, schedule arithmetic, and modular-arithmetic pipelines.
What a linear combination means and when a target is reachable
Given integers a and b, the set of all integer linear combinations a times x plus b times y is a fundamental object in elementary number theory. The Euclidean algorithm shows that this set coincides with the set of multiples of g, where g is the greatest common divisor of a and b. Equivalently, the linear Diophantine equation a times x plus b times y equals c has integer solutions if and only if g divides c.
When a solution exists, infinitely many solutions exist: if (x0, y0) is one particular solution, the general family is x equals x0 plus (b over g) times t and y equals y0 minus (a over g) times t for every integer parameter t. The constructive step that produces one particular solution is the extended Euclidean algorithm: while computing g it tracks how each remainder is written as a combination of the original a and b, and at termination it yields Bézout coefficients for g itself.
Multiplying those coefficients by the integer scale c over g yields a solution for the target c. When g does not divide c, the response still succeeds but sets possible to false and explains the obstruction, matching classroom language that the equation has no integer solution rather than pretending the client sent invalid data.
Where a linear combination calculator earns its keep
Contest programming and olympiad training repeatedly ask for integer solutions to a times x plus b times y equals c; a deterministic oracle that both certifies solvability via the gcd test and hands back coefficients cuts debug time on off-by-one scaling bugs. Engineering notebooks use two-coefficient combinations when reconciling periodic schedules, currency denominations, or gear-tooth counts that must hit an exact total. Cryptography and modular-arithmetic demos often start from the same extended Euclidean step before specialising to inverses when the gcd is one.
Failed validation does not consume balance.
What you can do with it
Linear Diophantine homework checks
Submit a, b, and target c to verify whether integer x, y exist for a·x + b·y = c and to obtain one particular solution plus the general parametric form.
Schedule and denomination arithmetic
Decide whether two step sizes can hit an exact total (shifts, coin counts, gear teeth) using the gcd divisibility rule and explicit coefficients.
FAQ
How do I express a target as a linear combination of two numbers?
Send integers a, b, and target c. If g divides c it returns integers x, y with a·x + b·y = c; otherwise possible is false.
When is there no integer solution?
When gcd(a,b) does not divide c. The response succeeds with possible set to false and a reason string; that is a mathematical no-solution, not a client validation error.
Are the coefficients unique?
No. If (x0,y0) works, so does x0+(b/g)·t and y0−(a/g)·t for every integer t.
What if a and b are both zero?
A linear combination of two zeros is not a well-defined generator set for a target value.
How do I check the coefficients it gives?
Multiply each number by its coefficient and add the results. For 15 and 25 with target 10, the pair 4 and −2 gives 15 × 4 + 25 × (−2), which equals 10, so the combination is correct.
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/algebra/linear-combination \
-H "Authorization: Bearer $KIT_KEY" \
-H "Content-Type: application/json" \
-d '{"a":15,"b":25,"c":10}'const res = await fetch("https://api.kit.forhosting.com/algebra/linear-combination", {
method: "POST",
headers: {
"Authorization": `Bearer ${process.env.KIT_KEY}`,
"Content-Type": "application/json"
},
body: JSON.stringify({
"a": 15,
"b": 25,
"c": 10
})
});
const { task_id } = await res.json();import os, requests
res = requests.post(
"https://api.kit.forhosting.com/algebra/linear-combination",
headers={"Authorization": f"Bearer {os.environ['KIT_KEY']}"},
json={
"a": 15,
"b": 25,
"c": 10
},
)
task_id = res.json()["task_id"]<?php
$res = file_get_contents("https://api.kit.forhosting.com/algebra/linear-combination", false, stream_context_create([
"http" => [
"method" => "POST",
"header" => "Authorization: Bearer " . getenv("KIT_KEY") . "\r\nContent-Type: application/json",
"content" => '{"a":15,"b":25,"c":10}',
],
]));
$task = json_decode($res, true);body := bytes.NewBufferString(`{"a":15,"b":25,"c":10}`)
req, _ := http.NewRequest("POST", "https://api.kit.forhosting.com/algebra/linear-combination", 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": 15,
"b": 25,
"c": 10
}Example response
{
"task_id": "tsk_a1b2c3d4e5f6a1b2c3d4e5f6",
"type": "algebra.linear_combination",
"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.
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
What a linear combination means and when a target is reachable
This calculator packages that full pipeline: it returns the gcd, a boolean possible flag, one particular (x, y) when the target is reachable, a numeric check equal to a times x plus b times y, a readable equation string, and general-form strings for the parametric family.
Input contract, response shape, and error behaviour
The pair a equals zero and b equals zero is also rejected, because a linear combination of two zeros is not a meaningful generator set for a target. On an unsolvable but well-formed instance, possible is false, x and y are omitted, and reason states that the gcd does not divide the target. Example: a equals fifteen, b equals twenty-five, c equals ten yields gcd five, possible true, and one valid pair x equals four and y equals negative two. Example of impossibility: a equals four, b equals six, c equals five yields gcd two and possible false because two does not divide five. POST a JSON body with three required integers: a and b, the coefficients of the combination, and c, the target value you want to express. Aliases first or m for a, second or n for b, and target or rhs for c are accepted for form-friendly clients. Each field may arrive as a JSON number, a digit string with an optional sign, or a bigint within the platform safe-integer absolute maximum; decimals, empty strings, missing fields, and values outside that range fail with invalid_input naming the field and are not billed. On a solvable instance the body includes the echoed a, b, and c; the non-negative gcd; possible set to true; integers x and y; check equal to the reconstructed combination; equation such as fifteen times four plus twenty-five times negative two equals ten; general_x and general_y strings that expose the free parameter t; and a short formula restating the divisibility criterion. Pair the response with your own stepper if you need every integer solution; this endpoint returns one particular solution plus the general form, not an infinite enumeration.
Integration use cases
Contest and programming oracles
Automate solvability tests and coefficient recovery for two-variable linear Diophantine tasks in online judges, generators, and unit tests.
Technical questions
What does the linear combination calculator cost?
The browser tool is free. API requests use prepaid KIT balance at $0.002 per successful call; invalid input is not billed.