ForHosting KIT · Math

Pernicious number checker

Count the ones in a number's binary form and see whether that count is prime: 13 is 1101 in binary, with 3 ones, so it is pernicious. Powers of two have a single one and never are. 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
N
13
You get
Binary
1101
One count
3

A pernicious number is a positive integer whose binary representation contains a prime number of one bits. This checker turns your decimal input into exact base-two notation, counts its ones, tests that small count for primality, and returns every useful intermediate value alongside a clear pernicious result. Inputs below one are rejected instead of being assigned an ambiguous classification.

What makes a number pernicious

The definition has two precise steps. First, write the positive integer n in base two without leading zeros. Second, count how many digits in that representation are ones; this quantity is often called the population count or Hamming weight.

The number n is pernicious exactly when that count is prime. For example, thirteen is written as 1101 in binary. It contains three ones, and three is prime, so thirteen is pernicious.

Fifteen is 1111, which contains four ones; four is composite, so fifteen is not pernicious. Powers of two such as eight have a single one. Because one is not a prime number, powers of two are not pernicious under the standard definition.

Only positive integers belong to this checker’s domain, so zero and negative values produce a validation error instead of a potentially misleading result.

Where this checker is useful

Pernicious numbers are a compact way to connect ordinary integer arithmetic, binary representation, combinatorics, and primality. In a classroom, the checker can confirm hand conversions while still showing enough intermediate information for students to find where their own work diverged. Researchers and recreational mathematicians can use it to filter candidate lists before studying gaps, residues, or intersections with other integer sequences.

A composite number may be pernicious when its binary one count is prime, and a prime number may fail the pernicious test when its one count is not prime. Keeping those distinct questions separate avoids a common interpretation error and makes the result useful as a focused building block.

Check number-theory homework

Confirm a decimal-to-binary conversion, the one-bit count, and the final pernicious classification in one response.

Filter integer datasets

Classify individual positive integers before analyzing pernicious-number gaps, patterns, or intersections with other sequences.

What is a pernicious number?

It is a positive integer whose binary representation contains a prime number of one bits.

Is one a pernicious number?

No. One is binary 1, which has one one bit, and one is not prime.

Is a pernicious number itself necessarily prime?

No. The prime test applies to the number of one bits, not to n itself; composite integers can be pernicious.

What inputs are rejected?

Missing values, values below one, fractions, scientific notation, non-decimal strings, and integers beyond the safe integer range are rejected.

Is 13 a pernicious number?

Yes. In binary 13 is written 1101, which contains three ones. Three is prime, so 13 is pernicious. The result shows the binary form and the count so you can check it by hand.

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/numth/pernicious-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/numth/pernicious-number \
  -H "Authorization: Bearer $KIT_KEY" \
  -H "Content-Type: application/json" \
  -d '{"n":13}'
{
  "n": 13
}
{
  "task_id": "tsk_a1b2c3d4e5f6a1b2c3d4e5f6",
  "type": "numth.pernicious_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.

It is suitable for number-theory exercises, sequence exploration, programming tests, and data validation where seeing the reasoning matters as much as receiving a boolean answer.

What makes a number pernicious

The response exposes binary, one_count, one_count_is_prime, and pernicious, rather than hiding the calculation behind one boolean. That makes it easy to inspect the conversion, teach the definition, or assert each stage in an automated test. The two boolean fields intentionally agree: one_count_is_prime names the mathematical test, while pernicious provides the direct classification callers usually need.

How to submit input and read the result

A leading plus sign is allowed in a string, but decimal points, exponent notation, hexadecimal prefixes, commas, and embedded spaces are rejected. After validation, the implementation converts the value to BigInt and asks for its base-two representation, ensuring that every displayed bit is exact even near the safe-integer boundary. It then scans the binary string once and increments a counter for every one. Since a safe integer has at most fifty-three significant binary digits, the subsequent primality check is tiny: it rejects counts below two, handles two, eliminates even counts, and tests odd divisors only through the square root. Send n as an exact JSON integer or as a plain decimal integer string. The preferred field name is n, while number and value are accepted aliases for convenient use with forms and existing datasets. The supported range ends at JavaScript’s maximum safe integer so the decimal input can be returned as a JSON number without rounding. Read binary to verify the base conversion, one_count to see the population count, one_count_is_prime to see the primality decision, and pernicious for the final answer. The algorithm has no network calls, random choices, current-time dependency, or mutable state, so identical inputs always produce identical JSON in the browser and API.

Where this checker is useful

Data engineers can also apply the API to validate labels generated by another system: compare that system’s binary string and population count with this deterministic result, then flag discrepancies without reusing the same implementation. Each successful API request costs $0.002; the browser path can be used interactively without charge. This tool classifies one integer per request and deliberately does not generate an unbounded sequence or search a range, which keeps runtime and billing predictable. It also does not claim that the input itself is prime.

Test a popcount implementation

Use deterministic outputs as fixtures when verifying bit-count code or a pernicious-number sequence generator.

What does the API cost?

Each successful API request costs $0.002. The interactive browser version is free.

Read the full KIT documentation →