Legendre symbol (a/p)
The Legendre symbol (2/7) is 1, so 2 is a square modulo 7: 3 times 3 is 9, which leaves 2. Enter any integer and odd prime to get 1, −1 or 0 with a plain-language reading of the result. Free in your browser.
- Free
- Runs in your browser
- No sign-up
- Your data stays on your device
Run — free
Worked example
- A
- 2
- Power (W)
- 7
- A mod
- 2
- Symbol
- 1
- Interpretation
- a is a quadratic residue modulo p
The Legendre symbol is the standard number-theoretic test for quadratic residuosity modulo an odd prime. Given an integer a and an odd prime p, the symbol (a/p) equals zero when p divides a, one when a is a non-zero square modulo p, and minus one when a is a quadratic non-residue. Cryptography courses, primality-related algorithms, cubic and quadratic reciprocity proofs, and contest-programming problems all lean on this three-valued indicator. Many languages expose modular exponentiation but leave the residuosity convention and the prime check to you. This calculator accepts a and p, verifies that p is an odd prime, applies Euler's criterion deterministically, and returns the symbol together with the reduced residue of a and a short interpretation so you can use the result without re-deriving the modular power by hand.
What the Legendre symbol means and why it matters
In modular arithmetic the question “does there exist an integer x with x squared congruent to a modulo p?” is fundamental. When p is an odd prime the answer collapses to three clean cases.
If a is divisible by p, every candidate square is also divisible by p only when a itself is zero modulo p, and the symbol is defined to be zero. If a is not divisible by p, either half of the non-zero residues are squares (the quadratic residues) and the other half are non-residues; the Legendre symbol is plus one for residues and minus one for non-residues.
This trichotomy appears in the law of quadratic reciprocity, in proofs that certain Diophantine equations have no solutions, in the analysis of the Tonelli–Shanks square-root algorithm, and in textbook presentations of the Miller–Rabin and Solovay–Strassen primality ideas that compare Euler’s criterion against a claimed Jacobi value. Rejecting composite or even moduli is part of the contract: the Legendre symbol is not defined for those moduli, and a silent Jacobi-style extension would mislead users who asked for Legendre specifically.
How this calculator evaluates (a/p) with Euler's criterion
Call the capability with integer fields a and p, where p must be an odd prime between three and one trillion inclusive, and a must be an integer whose absolute value is at most one trillion. The implementation first validates types and bounds, then runs a deterministic trial-division primality test on p. Euler’s criterion states that a raised to the power (p minus one) divided by two is congruent modulo p to the Legendre symbol.
The calculator computes that modular power with exact BigInt arithmetic so intermediate products never lose precision inside the published bounds. If the power is one the symbol is one. If the power is p minus one the symbol is minus one.
What you can do with it
Crypto and number-theory teaching labs
Instructors and students can check quadratic residuosity modulo odd primes on demand and see an explicit error when a sample modulus is composite or even.
Contest programming and reciprocity checks
Competitive programmers can verify Legendre values while solving reciprocity problems or validating that a square-root-mod-p step is justified.
FAQ
What happens if p is not an odd prime?
The message states that p must be an odd prime (for example when p is even or composite). Failed validation is not charged.
Which algorithm computes the symbol?
Euler's criterion: (a/p) ≡ a^((p−1)/2) (mod p). The modular power is evaluated with exact integer arithmetic after reducing a modulo p and verifying that p is an odd prime.
Is the Legendre symbol calculator free?
The browser tool runs free on your device.
What ranges of a and p are accepted?
p must be an odd prime from 3 through 1,000,000,000,000. a must be an integer whose absolute value is at most that same bound. Values outside those limits, or composite/even p, are rejected.
Is 2 a quadratic residue modulo 7?
Yes. The Legendre symbol (2/7) equals 1, which means some square leaves remainder 2 when divided by 7. For example, 3 squared is 9, and 9 divided by 7 leaves 2.
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/numth/legendre-symbol \
-H "Authorization: Bearer $KIT_KEY" \
-H "Content-Type: application/json" \
-d '{"a":2,"p":7}'const res = await fetch("https://api.kit.forhosting.com/numth/legendre-symbol", {
method: "POST",
headers: {
"Authorization": `Bearer ${process.env.KIT_KEY}`,
"Content-Type": "application/json"
},
body: JSON.stringify({
"a": 2,
"p": 7
})
});
const { task_id } = await res.json();import os, requests
res = requests.post(
"https://api.kit.forhosting.com/numth/legendre-symbol",
headers={"Authorization": f"Bearer {os.environ['KIT_KEY']}"},
json={
"a": 2,
"p": 7
},
)
task_id = res.json()["task_id"]<?php
$res = file_get_contents("https://api.kit.forhosting.com/numth/legendre-symbol", false, stream_context_create([
"http" => [
"method" => "POST",
"header" => "Authorization: Bearer " . getenv("KIT_KEY") . "\r\nContent-Type: application/json",
"content" => '{"a":2,"p":7}',
],
]));
$task = json_decode($res, true);body := bytes.NewBufferString(`{"a":2,"p":7}`)
req, _ := http.NewRequest("POST", "https://api.kit.forhosting.com/numth/legendre-symbol", 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": 2,
"p": 7
}Example response
{
"task_id": "tsk_a1b2c3d4e5f6a1b2c3d4e5f6",
"type": "numth.legendre_symbol",
"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 | 1000000000000 |
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 the Legendre symbol means and why it matters
Returning a structured object with symbol, a_mod, and interpretation saves callers from mapping a raw modular power of a to the conventional set {−1, 0, 1} and from forgetting that p equals two is excluded from the classical definition.
How this calculator evaluates (a/p) with Euler's criterion
Even values, composites, and p equal to two all fail with invalid_input and a message that names p; nothing is charged. When p is accepted, a is reduced to a_mod in the range zero through p minus one. If a_mod is zero the symbol is zero. Any other power would indicate a non-prime modulus and is treated as invalid_input for safety. The response includes a, p, a_mod, symbol, residue (true, false, or null when the symbol is zero), and interpretation.
Practical use, limits, pricing, and delivery
Use the browser tool when you want a quick residuosity check while reading a cryptography note, verifying a homework congruence, or debugging a square-root-mod-p routine. Accepted inputs are integers a with absolute value at most one trillion and odd primes p from three through one trillion. If you need the Jacobi symbol for composite odd moduli or an explicit modular square root when the symbol is one, use a dedicated capacity or algorithm; this tool deliberately stops at the Legendre trichotomy. Use the API when a script, grader, or educational platform needs many Legendre evaluations without embedding Euler’s criterion and a prime gate. Each successful request is one billable item at $0.002; validation failures and non-prime moduli do not consume balance. Results are deterministic: the same pair always yields the same symbol, the same a_mod, and the same interpretation string. Wire the endpoint into quadratic-reciprocity demos, contest-programming helpers, crypto teaching sandboxes, or any integer pipeline that already prefers exact arithmetic over approximate heuristics. Because the unit is a single item and the engine is pure parse, latency stays low and the free web channel mirrors the paid API without a second code path that could drift.
Integration use cases
Homework graders and symbolic pipelines
Automated graders and scripts can confirm (a/p) ∈ {−1,0,1}, detect non-prime p via invalid_input, and keep every intermediate product inside documented bounds.
Technical questions
How do I compute the Legendre symbol with this API?
Send JSON with integer fields a and p (p an odd prime) to numth.legendre_symbol. On success the response returns symbol in {−1, 0, 1}, plus a_mod, residue, and interpretation.