Research
Here I collect my research and code in computational number theory and exact algorithms.
I am mainly interested in lowering the complexity of discrete counting problems and series evaluations while keeping all calculations strictly in exact integer arithmetic.
The publications section contains my preprints and notes, together with short descriptions of the methods and links to the archived texts.
Selected Publications
-
Fast evaluation of the look-and-say sequence: lengths, digit counts and digits
Mark Kim · Dec 3, 2026 · DOI: 10.5281/ZENODO.24783043.The look-and-say sequence is defined by a(1) = 1 and a(n+1) = D(a(n)), where D replaces every maximal block of equal digits by its length followed by the digit. The word a(n) has length of order 1.3036^n, so it can be written down only for small n. We give algorithms for two problems whose answers are small: the length and the digit counts of a(n), and the digit of a(n) at a prescribed position. Conway's decomposition of a(n) into 99 atoms yields a 99 x 99 nonnegative integer matrix. We prove that the length of a(n) and the numbers of digits 1, 2, 3 in a(n) become, after a shift by 7 and the removal of explicit additive constants, solutions of one linear recurrence of order 71 whose characteristic polynomial is irreducible. All four numbers are therefore read off one residue x^{n-8} mod c(x), which is computed by a left-to-right chain of Kronecker squarings; the last squaring is replaced by a bilinear form. The cost is O(M(rn) + r^2 n) bit operations with r = 71. For the digit at a position we describe a block algorithm that replaces the table of lengths, which occupies about 19 n^2 bits, by checkpoints of x^e mod c and fixed-precision arithmetic for the decisions inside blocks; every answer is certified by an exact computation. In Python on one core, |a(n)| for n = 3 * 10^6, a number with 345,411 decimal digits, is computed in 7.1 seconds, and digits of a(3 * 10^5) are extracted within 370 MB of memory. -
The City-Building Sequence A400000 by Visibility Thresholds: An Exact Level-Structure Algorithm
Mark Kim · Nov 6, 2026 · DOI: 10.5281/ZENODO.24009232.The city-building sequence A400000 is defined by a(1) = 0 and a(n) = the least height h of a building at position n that sees exactly h earlier buildings. We attach to every earlier building i a visibility threshold T_i(n), the lowest height from which it is seen, and prove: a(n) is the least h with at most h thresholds less than or equal to h; exactly a(n) stored slopes change in step n; and the thresholds of buildings with a non-negative stored slope never decrease. These facts give an exact algorithm that keeps the buildings in a ladder of levels ordered by threshold and never rescans the past. The algorithm is proved correct, with exact integer arithmetic and a proved double-precision filter. Its running time is bounded by explicit statistics of the sequence itself: the number E_N = sum_{n <= N} a(n) of visibility edges, the stack size B_n and the lengths of gaps between terms above a height h. On N = 3 * 10^7 terms the output agrees with an independent pruned-scan implementation and with the published terms and record indices. The measured time at N = 3 * 10^7 is 4.119 s against 12.698 s for the pruned scan, and in Python 0.102 s against 13.436 s for the published generator at N = 2 * 10^4. -
Lattice Points of the ℓq-Ball in Time O(N^(2/(3q)) log² N)
Mark Kim · Nov 5, 2026 · DOI: 10.5281/ZENODO.23969822.The sequences A175363 = C_3(n) and A175364 = C_3(n^2), where C_q(N) is the number of integer pairs (x,y) satisfying |x|^q + |y|^q <= N, are traditionally defined by sums of Theta(N^(1/q)) integer roots. We compute C_q(N) in O(N^(2/(3q)) * log^2 N) operations on O(log N)-bit integers: O(n^(2/9) * log^2 n) for A175363 and O(n^(4/9) * log^2 n) for A175364, compared to the classical Theta(n^(1/3)) and Theta(n^(2/3)) direct methods. By symmetry, the count reduces to the lattice points under a concave arc. The upper hull of these points has O(N^(2/(3q))) vertices by Andrews' theorem, the column sums along a hull edge are given in closed form, and the next edge is the steepest admissible primitive vector. This vector is found by a Stern-Brocot descent whose runs are located by exponential search with exact integer predicates, including an exact test for the sign of the derivative. All claims are proved. On one core in Python 3.12, A175363(10^24 + 12345) takes 56.68 s with the direct method and 1.399 s with the new method (40.5 times faster); the method computes A175363(10^33 + 12345) in 212.1 s. A175364(10^12 + 12345) takes 53.06 s directly and 1.548 s with the method (34.3 times faster), and A175364(10^16 + 12345) (where N is approximately 10^32) takes 130.2 s. For q = 4 and N = 10^28 + 12345 the times are 4.765 s and 0.251 s (19.0 times), and N = 10^36 + 12345 takes 7.616 s. All values agree with the direct method wherever both were run. -
Folding the Plouffe-Bellard Digit-Extraction Scheme for π: A Legendre-Symbol Block Identity and an O(n^(3/2)) Variant
Mark Kim · Nov 3, 2026 · DOI: 10.5281/ZENODO.23931336.The algorithm of Plouffe and Bellard computes the digits of Pi at positions n+1,...,n+g in any base from the series Pi = 2 * Sum_{k>=0} k!/(2k+1)!! in O(n^2) operations on machine words and O(1) words of memory: for each of the pi(2N) primes q < 2N with N approx. n*log2(10) it runs a loop of length N. We prove that for every prime q with q^2 > 2N + q the sum of the contributions of all complete blocks k = j (mod q) collapses to the Legendre symbol (-1/q), by the identity Sum_{i=0}^{(q-1)/2} binomial(2i, i) * 2^(-i) = (-1)^((q-1)/2) (mod q). The loop of length N is replaced by a partial sum of at most min(L, h - L + 1) terms, where h = (q - 1)/2, and the total number of loop iterations drops from (2 + o(1)) * N^2 / ln N to at most (7/24 + o(1)) * N^2 / ln N, a reduction factor of at least 6.8. Each remaining partial sum is a prefix or suffix sum of a hypergeometric sequence modulo q; computing it with the baby-step giant-step method of Bostan, Gaudry and Schost takes O(sqrt(L) * log L) operations and gives a total complexity of O(n^3/2) operations. The proposed framework returns the correct digits in all verification cases; on benchmarks with n = 2000,...,32000 it is 4.2 to 18.7 times faster than the standard loop of the Plouffe-Bellard scheme on the same series, and the measured execution time of a single tail sum scales strictly like sqrt(L) up to L = 4.1 * 10^7. The complete source code, verification test suites, and benchmarks are made available. -
A Short-Window Closed Formula for the n-th Prime Number: A Refinement of the Ruiz–Sondow Formula with 0.787 n/ln² n Terms
Mark Kim · Oct 26, 2026 · DOI: 10.5281/ZENODO.23662114.Let p(n) be the n-th prime number (OEIS A000040) and pi(x) the prime counting function. The classical closed-form formula of Ruiz and Sondow quoted in A000040 requires the summation of approximately 2*n*ln(n) terms, while the formulas of Willans and of Gandhi, Golomb and Wang require exponentially many terms. We prove that for every pair of integer-valued functions A(n) <= p(n) <= B(n) with A >= 1 and B = 8,009,824, the resulting refined formula requires at most 0.787*n / ln^2(n) + 1 terms, which narrows the summation range of the Ruiz-Sondow formula by a factor of ~2.54*ln^3(n). This constitutes a reduction of 3,500 times for n=10^6 and 23,000 times for n=10^9. The underlying analytical bounds were validated numerically for all n <= 13,161,544, and the formula was cross-verified against independent computations up to n = 10^10. Evaluated exactly via a localized window sieve, it computes p(10^9) in 0.30 s and p(10^10) in 4.2 s in Python.
Recent Work
| Dec 6, 2026 |
Capacity of the bands of line counts of point sets with a long line DOI: 10.5281/ZENODO.24899474 |
| Dec 4, 2026 |
Enumerating integers whose sum of divisors is a square DOI: 10.5281/ZENODO.24783043 |
| Dec 4, 2026 |
Enumerating integers whose sum of divisors is a square DOI: 10.5281/ZENODO.24783043 |
| Dec 3, 2026 |
Fast evaluation of the look-and-say sequence: lengths, digit counts and digits DOI: 10.5281/ZENODO.24783043 |
| Dec 2, 2026 |
Growth of the number of multiplicity histograms of linear spaces DOI: 10.5281/ZENODO.24759898 |