Proth primality test
The Proth primality test checks a number written as k × 2^n + 1 by applying Proth's theorem to a witness you provide.
Run — free
It first verifies that k is positive and odd, n is positive, and k is smaller than 2^n. It then computes the required modular power exactly with integer arithmetic. A successful congruence is a proof that the Proth number is prime; an unsuccessful witness is reported honestly as inconclusive unless it reveals a factor.
Enter a genuine Proth number and a witness
A Proth number has the precise form N = k × 2^n + 1, where k is a positive odd integer, n is a positive integer, and k is strictly less than 2^n. All of those conditions matter. This calculator accepts k and the witness as decimal text so large values stay exact instead of being rounded by ordinary floating-point input. Enter n as an integer from 1 through 10,000. The calculator constructs N rather than asking you to supply it separately, which prevents a mismatch between a claimed number and its defining parameters. It also checks that the witness lies strictly between 1 and N. Inputs with an even k, a nonpositive value, or k greater than or equal to 2^n are rejected as non-Proth inputs instead of being passed through a theorem whose assumptions do not apply. The returned number, exponent, witness, and residue are decimal strings where necessary, making the calculation auditable and safe to copy into another exact-arithmetic tool.
Understand what the congruence proves
For a valid Proth number N, Proth's theorem says that N is prime if there is an integer a for which a^((N−1)/2) is congruent to −1 modulo N. The supplied witness is a, and the calculator evaluates that modular power by repeated squaring without constructing the enormous ordinary power first. In the output, `residue` is the least nonnegative residue and `passes_test` is true exactly when it equals N−1, the modular representation of −1. In that case, `prime_proven` is true and the verdict is `prime`; this is a deterministic certificate under the already validated Proth conditions, not a probable-prime guess. The output includes the exact exponent (N−1)/2 so you can reproduce the congruence independently. The algorithm uses only integer operations, has no random witness selection, and does not consult a table or remote service. Repeating an input therefore returns the same result and exposes every important value used in the theorem.
Treat a failed witness correctly
A witness that does not produce −1 does not, by itself, prove that the number is composite. It only means that this particular witness did not satisfy the sufficient condition in Proth's theorem. For that reason, the calculator returns `inconclusive` rather than `composite` when the residue differs and the witness is coprime to N. You may then try another mathematically chosen witness or use a different deterministic primality method. There is one useful exception: before interpreting the congruence, the calculator computes the greatest common divisor of the witness and N. If that value is a proper factor, the result is conclusively `composite` and the factor is returned. This distinction prevents the common mistake of turning a one-way theorem into an invalid two-way test. It also makes the capability useful in automated workflows: accept `prime` as a proof, reject `composite` when a factor appears, and route `inconclusive` for another test rather than silently treating it as failure.
What you can do with it
Verify a candidate from a search
Check a generated k and n pair with a selected witness before recording the candidate as proven prime.
Teach Proth's theorem
Show students the exact exponent, modular residue, and distinction between a proof and an inconclusive witness.
Add a deterministic pipeline check
Validate the Proth preconditions and route prime, composite, and inconclusive outcomes without floating-point arithmetic.
FAQ
What does the API request cost?
Each API request costs $0.002. The calculation is also suitable for the free browser runner.
What makes an input a Proth number?
It must equal k × 2^n + 1 with positive odd k, positive n, and k < 2^n.
Does a failed witness prove compositeness?
No. It is normally inconclusive. Compositeness is reported only when the supplied witness exposes a nontrivial common factor.
Why are k and witness entered as strings?
Decimal strings preserve integers larger than JavaScript's safe numeric range without rounding.
Is a passing result probabilistic?
No. Once the Proth conditions are validated, the required congruence is a proof of primality under Proth's theorem.
Are witnesses selected automatically?
No. You supply the witness, and the capability deterministically tests that exact value.
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/proth-test \
-H "Authorization: Bearer $KIT_KEY" \
-H "Content-Type: application/json" \
-d '{"k":"3","n":3,"witness":"3"}'const res = await fetch("https://api.kit.forhosting.com/numth/proth-test", {
method: "POST",
headers: {
"Authorization": `Bearer ${process.env.KIT_KEY}`,
"Content-Type": "application/json"
},
body: JSON.stringify({
"k": "3",
"n": 3,
"witness": "3"
})
});
const { task_id } = await res.json();import os, requests
res = requests.post(
"https://api.kit.forhosting.com/numth/proth-test",
headers={"Authorization": f"Bearer {os.environ['KIT_KEY']}"},
json={
"k": "3",
"n": 3,
"witness": "3"
},
)
task_id = res.json()["task_id"]<?php
$res = file_get_contents("https://api.kit.forhosting.com/numth/proth-test", false, stream_context_create([
"http" => [
"method" => "POST",
"header" => "Authorization: Bearer " . getenv("KIT_KEY") . "\r\nContent-Type: application/json",
"content" => '{"k":"3","n":3,"witness":"3"}',
],
]));
$task = json_decode($res, true);body := bytes.NewBufferString(`{"k":"3","n":3,"witness":"3"}`)
req, _ := http.NewRequest("POST", "https://api.kit.forhosting.com/numth/proth-test", body)
req.Header.Set("Authorization", "Bearer "+os.Getenv("KIT_KEY"))
req.Header.Set("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)Example request
{
"k": "3",
"n": 3,
"witness": "3"
}Example response
{
"task_id": "tsk_a1b2c3d4e5f6a1b2c3d4e5f6",
"type": "numth.proth_test",
"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_n | 10000 |
max_decimal_digits | 3011 |
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. |