ForHosting KIT · Math

Jacobsthal number calculator

Enter a whole number n from 0 to 40 and get the nth Jacobsthal number exactly: the sequence runs 0, 1, 1, 3, 5, 11, 21, 43, and J(40) is 366503875925. Each term is the previous one plus twice the one before. Free in your browser.

  • Free
  • Runs in your browser
  • No sign-up
  • Your data stays on your device
Use it from WebAPIEmailTelegramApp soon
If you enter
Index n
0
You get
Jacobsthal number
0

Compute the nth Jacobsthal number from a single integer n between 0 and 40. The tool returns n and its value using the closed form J(n) = (2^n - (-1)^n)/3, equivalent to the recurrence J(n) = J(n-1) + 2·J(n-2).

A sequence that hugs the powers of two

The Jacobsthal numbers start with 0 and 1, and every later term is the previous one plus twice the one before it: 0, 1, 1, 3, 5, 11, 21, 43, 85, 171, 341. Each term is roughly double the last. In fact each one is the whole number nearest to 2 to the power n divided by 3, landing alternately just above and just below it. That is why a closed formula exists: take 2 to the power n, subtract 1 when n is even or add 1 when it is odd, and divide by 3. The division never leaves a remainder, so the result is always a whole number.

Where they turn up, and what to watch

They appear in tiling problems, Cunningham chains and 2-adic identities, and they make a convenient reference when you test your own code or formula against the published sequence A001045. Teachers use them to show that a recurrence and a closed formula produce the same numbers. Two details trip people up. The count starts at J(0), which is 0, so J(1) and J(2) are both 1. And n must be a whole number from 0 to 40: that cap keeps every value exact, with J(40) at 366503875925, while values such as 2.5 or negative numbers are refused.

The Jacobsthal sequence

The Jacobsthal numbers start J(0) = 0 and J(1) = 1, then follow the recurrence J(n) = J(n-1) + 2·J(n-2), giving 0, 1, 1, 3, 5, 11, 21, 43, 85, 171, 341 and so on. Each term is roughly double the previous one, since consecutive Jacobsthal numbers alternate just above and below powers of two; they are the integers nearest to 2^n/3.

How the value is computed

Rather than iterating the recurrence, the implementation evaluates the closed form J(n) = (2^n - (-1)^n)/3 directly. It computes 2^n with arbitrary-precision BigInt arithmetic, subtracts 1 when n is even and adds 1 when n is odd (that is the (-1)^n term), and divides by 3, which is always exact because 2^n - (-1)^n is provably divisible by three. The exact BigInt result is then converted to a JavaScript number.

Combinatorics and number theory

Look up an exact Jacobsthal term when working with tilings, Cunningham chains or 2-adic identities.

Sequence and OEIS work

Generate reference values of J(n) to check code or a formula against A001045 without a local library.

Teaching recurrences

Show that the closed form (2^n - (-1)^n)/3 matches J(n) = J(n-1) + 2·J(n-2) for each n.

What does it return?

An object with your n and value, the nth Jacobsthal number computed from J(n) = (2^n - (-1)^n)/3.

Why is n limited to 40?

So the exact BigInt result fits in the 2^53 safe-integer range; J(40) is 366503875925, with no precision loss.

Is the result exact?

Yes. Jacobsthal numbers are integers and the division by three is always exact, so there is no rounding.

Where are Jacobsthal numbers used?

In combinatorics and number theory, for example in tiling problems, Cunningham chains and 2-adic identities. They are also handy reference values when you check your own code or formula against the published sequence A001045.

Is there a formula that skips the step-by-step sequence?

Yes. Raise 2 to the power n, subtract 1 if n is even or add 1 if it is odd, then divide by 3. For J(3) that is 8 plus 1, which is 9, divided by 3: the answer is 3, and the division is always exact.

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.

POSThttps://api.kit.forhosting.com/math/jacobsthal-number

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.

curl -X POST https://api.kit.forhosting.com/math/jacobsthal-number \
  -H "Authorization: Bearer $KIT_KEY" \
  -H "Content-Type: application/json" \
  -d '{"n":5}'
{
  "n": 5
}
{
  "task_id": "tsk_a1b2c3d4e5f6a1b2c3d4e5f6",
  "type": "math.jacobsthal_number",
  "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.

Per request$0.002

Published price — no tokens, no invented credits. A failed task is never charged.

HTTPCodeMeaning
401unauthorizedMissing or invalid API key.
402insufficient_balanceYour balance doesn't cover the task price.
404unknown_typeThat task type doesn't exist.
429rate_limitedToo many requests. Use the webhook instead of polling.

The Jacobsthal sequence

This calculator takes a single non-negative integer n through the required field n and returns an object with that n echoed back and its value, the nth term of the sequence.

How the value is computed

The domain is capped at n = 40 precisely so the answer stays within the 2^53 safe-integer range and never loses precision in that conversion: J(40) is 366503875925, well under the limit. This is why the tool is deterministic and reproducible, with no accumulated floating-point drift from summing many prior terms.

Input rules and errors

The single field n must be an integer in the inclusive range 0 to 40. There is no decimals parameter and no optional configuration, so requests are minimal and unambiguous. Anything else raises a typed invalid_input error with the message "n inválido": a negative value, a value above 40, a non-integer such as 2.5, a string, or a missing field all fail the same check before any computation runs. The worked example passes n = 0 and receives value 0, the first term of the sequence. Because validation happens up front and the arithmetic is exact, failures are cheap and safe to retry, and the machine-readable error code lets a client distinguish a bad request from a transport problem.

What input is invalid?

Non-integers, negatives, values above 40, or a missing n return a typed invalid_input error reading "n inválido".

Is it free?

Yes in the browser as a tier A widget. The deterministic API costs $0.002 per successful call; failed tasks are not charged.

Read the full KIT documentation →