Integer arithmetic in which storage grows with the number of numerical digits needed, instead of imposing a fixed word size. It allows exact addition, multiplication, and exponentiation on large integers, subject to available memory; operation costs grow with operand length.
Balanced number Created 2026-10-20 Updated 2026-11-05
A balanced number is a positive integer whose first decimal digits have the same digit sum as its last decimal digits, where is the number of numerical digits. For odd , the middle numerical digit appears on both sides and cancels, so only the equally long outer halves need to be compared.
For example, is balanced because . It is not a palindromic number: equality of two digit sums does not require reversed digits. At odd length, is balanced because the outer pairs and both sum to three; its middle digit is irrelevant to the equality.
Digit dynamic programming can tabulate counts and value sums of fixed-length halves indexed by digit sum, then match equal indices. The first half must begin with a nonzero numerical digit, while the last half may contain initial zeros, as in . Preserving the half length is essential when assembling the positional value.
Bouncy number Created 2026-10-20 Updated 2026-11-05
In decimal representation, a bouncy number is a positive integer whose sequence of numerical digits is neither nondecreasing nor nonincreasing from left to right. Equivalently, one adjacent pair strictly rises and another strictly falls. For example, is bouncy, while and are not. Repeated numerical digits are permitted by the weak order conditions: is nondecreasing.
A number satisfying both weak order conditions has every numerical digit equal, so the overlap consists exactly of the positive repdigits, such as . If count the nondecreasing, nonincreasing and repdigit positive integers at most , respectively, inclusion-exclusion gives the count of bouncy numbers as
This reduces counting the complement of two monotonicity conditions to counting those two simpler families and their explicit overlap.
Circular prime 2026-10-20
A prime number for which every cyclic rotation of its numerical digits is also a prime number. In decimal representation, is an example because are all prime numbers. A multi-digit circular prime can contain only : any other digit can be rotated into the units position and force divisibility by or .
Digital root Created 2026-10-20 Updated 2026-11-05
The digital root of a nonnegative integer in integer radix is the single numerical digit obtained by repeatedly taking its digit sum. For example, in decimal representation, , while .
The process terminates: if , some nonzero digit occupies a position above the units, so . The positive integers therefore decrease until a single numerical digit remains. Each step preserves the integer congruence class modulo .
For positive inputs, every digit sum stays positive. The final digit lies in , rather than . Choosing the representative in this range gives
with . This explains why a positive multiple of has decimal digital root , not zero. The formula combines modular arithmetic with the positivity of the terminating representative.
Digit dynamic programming 2026-10-20
Count or sum integers by processing their numerical digits and merging prefixes that have the same possible continuations. Typical state records include the current position, whether the prefix still equals an upper limit, a remainder, or a bit mask of digits already used. The final answer comes from accepting exactly those states satisfying the desired digit constraints.
Digit permutation 2026-10-20
A rearrangement of the numerical digits of a numeral. Two numerals have the same digit permutation class exactly when their digit multisets agree. If they represent numbers of the same length, a leading zero must be disallowed.
Digit sum Created 2026-10-20 Updated 2026-11-05
The digit sum of a nonnegative integer in a specified radix is the sum of its numerical digits. If
write , with . For example, . In binary representation, the digit sum is the Hamming weight of the digit string.
Since , the positional expansion gives
In decimal representation, this yields the familiar divisibility tests by and : the integer and its digit sum have the same remainder modulo either. For , both and leave remainder modulo . The argument explains the rule from modular arithmetic, rather than relying on a pattern noticed in examples.
A least-significant-digit radix sort processes numerical digits from smallest to largest place value. Fix integers and , and take complete sorting records whose sort keys satisfy . Use exactly positions in positional notation with radix , including leading zeros. At pass , apply a stable digit sort to the current array using
The floor function selects the integer quotient, and the remainder selects the current numerical digit. Move the complete sorting record, including its associated data. There are exactly passes, so this procedure terminates even for an empty array. The radix sort suffix invariant supplies its algorithm correctness argument.
For an original input, let the letters identify the attached data:
Here , , and leading zeros only align place values; represents the integer five. The exact pass ledger is:
After the units pass, the numerical digits are . The ties retain before and before before . This array is not yet ordered by its whole integer sort keys: still precedes . After the tens pass, the two-position suffixes are . In particular, now precedes : their tens numerical digits differ, so stable sorting does not require retaining their previous order. The hundreds pass produces the final sorted array, with all attached letters preserved.
Figure 1.
Three stable digit passes order successively longer suffixes
. Original decimal radix sort ledger. Each card carries an unchanged record label. Orange marks the numerical digit read in the current pass; green marks lower positions already processed. The suffix row beneath each pass shows precisely what is ordered, rather than claiming whole-key sortedness early. Details.
Numeral Created 2026-10-14 Updated 2026-11-05
A numeral is a written expression representing a number. The number five can be written as the decimal numeral , the binary numeral , or the Roman numeral V. The expressions differ while the represented integer is the same.
This distinction matters when an algorithm examines numerical digits. A palindromic number, for example, is defined through its representation in a specified radix, rather than through the appearance of an abstract number. The integer five is a palindrome as the one-digit decimal numeral and as the binary numeral , whereas ten is written in decimal and in binary, neither of which is a palindrome.
Numerical digit Created 2026-10-14 Updated 2026-10-20
A numerical digit is one symbol in a positional notation string, denoting an integer from zero through one less than the radix.
Pandigital number 2026-10-20
A number whose representation contains every numerical digit from a specified alphabet. The convention must specify the base, whether zero is required, and whether repetitions are allowed. In many counting problems, “0-to-9 pandigital” means that all ten decimal numerical digits occur exactly once; other problems require only that each occur at least once.
Prime-proof number Created 2026-10-20 Updated 2026-11-05
An integer for which replacing any one decimal numerical digit by a different digit never produces a prime number. The convention must specify whether changes creating a leading zero are permitted. An exact test enumerates the allowed substitutions and applies primality testing to each result.
Radix sort key encoding 2026-10-18
An encoding for radix sort must make the intended total order of sort keys agree with the lexicographic order of its fixed-width numerical digit tuples. The positional notation for bounded nonnegative integers has this property. At the most significant differing position , a one-unit numerical digit difference contributes , while all lower positions together contribute at most
This geometric series shows why lower numerical digits cannot reverse that comparison. Leading zero padding works here because it preserves place values and the represented integer.
For signed integers in a known integer interval , encode and choose with . This order-preserving function is also injective: exactly when . For , the four-bit encodings of are after adding eight. Restore the original signed sort keys when displaying the complete sorting records; the encoding need not replace their data. Sorting the unsigned values of raw two's complement bit patterns would put nonnegative integers before negative ones, so their representation alone is not this ordered encoding.
For variable-length strings, first specify the alphabet order and whether a proper prefix precedes its extensions. As an original construction, use , let every string have length at most three, encode as one and as two, and append zeros to width three. Zero is reserved for an end marker strictly below every real symbol. The strings encode as in radix three, which preserves their lexicographic order. A differing real symbol decides the comparison; at a prefix boundary, the shorter string's zero comes before the extension's one or two. Left padding would instead encode as and as , reversing . Padding raw bytes with zero also fails if zero is an allowed data symbol: distinct strings can then receive the same encoding. A reserved end marker and an explicit symbol ordering are essential; byte order alone does not establish a desired human text order.
Figure 1.
Stable ties preserve lower digits; suitable encodings preserve the intended order
. Original counterexample above: reversing a tens tie destroys the units order and a later stable hundreds pass cannot repair it. Below: signed integer offsets and a reserved end marker for bounded strings produce increasing fixed-width encodings. All entries are exact constructed examples. Details.
After passes, , the array is in nondecreasing order of , the integer represented by its lowest numerical digits. Equivalently it is ordered by the tuple under lexicographic order, with the most significant processed numerical digit first. Among equal suffixes it retains the original order of the complete sorting records.
The loop invariant has a simple mathematical induction proof. Before any pass, for every sort key, so the original array satisfies it. Suppose it holds after passes. The next stable digit sort puts smaller groups first and preserves the existing order within each tie. Since
the new array is ordered by . Equal new suffixes have equal current numerical digits and equal old suffixes, so their original order is also preserved. Every pass is a permutation of complete sorting records, establishing sorting permutation preservation. At termination , the assumption gives : the invariant becomes whole-key sortedness, together with stable sorting.
Repunit Created 2026-10-20 Updated 2026-11-05
In a positional notation of integer radix , a repunit is a repdigit whose numerical digits are all . A length- repunit, with , is the geometric series
For example, , while . The same string has different values in different radices.
Appending one numerical digit gives . Thus remainders modulo a positive integer obey , starting with . This recurrence relation avoids constructing huge integers. For decimal repunits modulo , the successive remainders are ; hence the six-digit repunit is divisible by .
A repunit divisible by exists exactly when are coprime integers, and one then exists with at most digits. Necessity follows because a common prime factor of divides every nonconstant term of , leaving remainder one. For sufficiency, examine modulo . If none is zero, the pigeonhole principle gives equal remainders at two indices . Their difference is . Cancelling the invertible factor modulo produces a divisible repunit of length .
Reversible number Created 2026-10-20 Updated 2026-11-05
A reversible number is a positive integer whose sum with its digit reversal has numerical digits that are all odd integers. Here the radix is ten, and reversing must preserve the digit length: the original number cannot end in zero, because that would create a leading zero after reversal.
For example, , so both and satisfy the rule. The example shows that internal zeros are allowed. In contrast, is excluded by the reversal-length condition, even though has odd digits.
The arithmetic carries couple mirrored digit positions. In , the units sum creates a carry, which makes the next digit . Treating the digit pairs independently would miss this dependence. A counting method can instead track carries from both ends and match them in the middle, avoiding enumeration of every integer of a given length.
Stable digit sort 2026-10-18
A stable digit sort applies stable sorting to complete sorting records using one specified numerical digit of their encoded sort keys. Counting sort can supply it; stable record placement in counting sort moves records without discarding their associated data. Stability concerns equal current numerical digits, even when the full sort keys differ. This is the information-preservation step in least-significant-digit radix sort.[ref]
An original two-record counterexample exposes the need for the tie rule. Start with at width three. A units pass gives . Both tens numerical digits are four. A deliberately unstable tens pass may reverse their tie and return : it is sorted by the tens numerical digit, yet its two-position suffixes are decreasing. The final stable hundreds pass sees two zeros and keeps this wrong order. Sorting permutation preservation still holds, but sortedness fails. Stability in the tens pass would have retained the units information.
With counting sort as the stable digit sort, each pass initializes counters, counts current numerical digits, constructs their prefix sums, and places complete sorting records. Thus each pass costs , and passes cost in Big O notation. Reuse the counters and two arrays of record references between passes: auxiliary space complexity is , rather than . Assume constant-cost numerical digit extraction, counter arithmetic, array indexing and record-reference movement; the bound counts these operations, not the cost of copying arbitrarily large payloads or performing arbitrary-precision integer arithmetic.
The benefit is avoiding a counter for every possible whole sort key: width has possibilities, while each pass needs only counters. A larger radix reduces the number of passes for a fixed key range but enlarges the counter array. The comparison sorting lower bound does not apply to these direct array indices; they reveal more than a two-way comparison. Nor does fixing make disappear: growing key width still increases work.