Two-coin representable checker
The two-coin representable checker determines whether a non-negative target can be formed using any non-negative number of two specified coin denominations.
Run — free
The denominations must be coprime, which gives the problem a precise modular-arithmetic solution. When the target is representable, the result includes one exact pair of coin counts; otherwise, it clearly reports that no such pair exists. This is useful for numerical experiments, discrete mathematics exercises, denomination design, and validating exact-size combinations without an exhaustive search.
Define the two-coin problem precisely
Enter two positive integer coin denominations as coin_a and coin_b, then enter a non-negative integer target. The checker asks whether there are non-negative integers count_a and count_b for which the first count times coin_a plus the second count times coin_b equals the target exactly. A representable result therefore means more than finding a nearby value or a combination below a budget: the equality must be exact, and neither count may be negative. Zero is a valid target because choosing zero of each coin produces it. A denomination of one is also valid and makes every non-negative target representable. All three inputs must be safe integers, so decimal values, numeric strings, infinities, and integers beyond JavaScript's exact safe range are rejected instead of being silently rounded. The two denominations must additionally be coprime. That means their greatest common divisor is one, a condition the checker validates before attempting to solve the target.
Understand the modular calculation
Because the denominations are coprime, the first coin has a multiplicative inverse modulo the second coin. The checker computes that inverse with the extended Euclidean algorithm, then uses it to identify the unique candidate count_a between zero and coin_b minus one that satisfies the required congruence. Subtracting the value contributed by those first coins leaves a remainder. If the remainder is non-negative, it is divisible by coin_b and yields a valid count_b; the response includes both counts as a concrete witness. If that remainder is negative, no non-negative representation exists. This conclusion is complete, not heuristic: every other integer solution changes count_a by a whole multiple of coin_b while changing count_b in the opposite direction by a whole multiple of coin_a. Starting from the smallest non-negative candidate for count_a means that a negative remainder cannot be repaired without making count_a negative. The method runs in logarithmic time rather than testing many possible coin counts one by one.
Interpret results and input errors
A response with representable set to true includes count_a and count_b, and multiplying those counts by their corresponding denominations reconstructs the target. The returned pair is one valid witness; a sufficiently large target can have several different representations, and the checker does not claim to enumerate or optimize all of them. A false response omits the count fields because no pair applies. Treat a non-coprime error differently from a false result. False means the input met the capability's contract but the particular target cannot be formed. An error means the denomination pair is outside this capability's defined domain, so no representability decision is returned. For example, coins 6 and 9 share a factor of 3 and are rejected even when the target is divisible by 3. This deliberate distinction prevents a domain violation from being mistaken for a mathematical impossibility. The computation is deterministic, uses no network service, and returns the same result for the same exact integer inputs in both browser and API contexts.
What you can do with it
Check an exact payment amount
Determine whether two available denominations can produce a required total and obtain one pair of counts when they can.
Verify a number theory exercise
Test a proposed target for a coprime denomination pair and compare the returned witness with a hand calculation.
Validate fixed-size combinations
Model two coprime package sizes as coins and check whether an exact requested quantity can be assembled without partial packages.
FAQ
What does representable mean?
It means the target equals coin_a times count_a plus coin_b times count_b for some non-negative integer counts.
Why must the coins be coprime?
This capability uses the coprime two-coin contract, which guarantees the modular inverse used by its direct algorithm. A pair with a greater common divisor is rejected as invalid input.
Does a true result include a combination?
Yes. It returns count_a and count_b as one exact non-negative combination that reconstructs the target.
Does it return every possible combination?
No. It decides representability and returns one witness when one exists; it does not enumerate or optimize all possible pairs.
Can the target be zero?
Yes. Zero is representable by using zero coins of each denomination.
How much does an API request cost?
Each API request costs $0.002. The browser version can run the same deterministic calculation locally.
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/numth/coin-representable-two \
-H "Authorization: Bearer $KIT_KEY" \
-H "Content-Type: application/json" \
-d '{"coin_a":4,"coin_b":7,"target":23}'const res = await fetch("https://api.kit.forhosting.com/numth/coin-representable-two", {
method: "POST",
headers: {
"Authorization": `Bearer ${process.env.KIT_KEY}`,
"Content-Type": "application/json"
},
body: JSON.stringify({
"coin_a": 4,
"coin_b": 7,
"target": 23
})
});
const { task_id } = await res.json();import os, requests
res = requests.post(
"https://api.kit.forhosting.com/numth/coin-representable-two",
headers={"Authorization": f"Bearer {os.environ['KIT_KEY']}"},
json={
"coin_a": 4,
"coin_b": 7,
"target": 23
},
)
task_id = res.json()["task_id"]<?php
$res = file_get_contents("https://api.kit.forhosting.com/numth/coin-representable-two", false, stream_context_create([
"http" => [
"method" => "POST",
"header" => "Authorization: Bearer " . getenv("KIT_KEY") . "\r\nContent-Type: application/json",
"content" => '{"coin_a":4,"coin_b":7,"target":23}',
],
]));
$task = json_decode($res, true);body := bytes.NewBufferString(`{"coin_a":4,"coin_b":7,"target":23}`)
req, _ := http.NewRequest("POST", "https://api.kit.forhosting.com/numth/coin-representable-two", body)
req.Header.Set("Authorization", "Bearer "+os.Getenv("KIT_KEY"))
req.Header.Set("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)Example request
{
"coin_a": 4,
"coin_b": 7,
"target": 23
}Example response
{
"task_id": "tsk_a1b2c3d4e5f6a1b2c3d4e5f6",
"type": "numth.coin_representable_two",
"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. |