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
-
The Look-and-Say Sequence: Terms in Output-Linear Time and Digits in O(n) Steps
Mark Kim · Nov 10, 2026 · DOI: 10.5281/ZENODO.24109380.Let a(n) be the n-th term of the look-and-say sequence (A005150), a(1)=1, a(n+1)=D(a(n)), where D writes the length of every run of equal digits followed by the digit, and let |a(n)| ~ 1.567 * lambda^n be its number of digits, lambda=1.3036 (A005341). Every term is a concatenation of strings from a set A of 99 strings, the 92 Conway elements and 7 transient words, and A is generated by a cut test and verified by a finite closure check that proves a(t+1) is the product of x over w_t for the word w_t = sigma^t(1). This gives three exact algorithms: the whole term a(n) in |a(n)|(1+o(1)) bytes of memory copy plus O(lambda^(n/2)) other operations, which is optimal because the output has that size; any digit or block of a(n) in O(n) steps on big integers, without building the term; and the length |a(n)| and the numbers of digits 1,2,3 in a(n) from linear recurrences of order at most 79 (order 72 for the length), proved by a finite residual check. All claims are proved. In Python, a(68) with 105,745,224 digits takes 0.05 s, 48 times less than stepwise expansion over Conway elements; |a(10^5)| takes 0.99 s and |a(10^6)| takes 36.9 s; a digit of a(3000) at position 10^300 is read in 0.96 ms. The OEIS table of A005150 stops at n=25. -
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
| 17 November 2026 |
Counting integer right triangles by perimeter in time O(N^2/3 log^2 N): an exact formula without gcd conditions, a hull walk under the hyperbola, and new terms of the sequence A299706 DOI: 10.5281/ZENODO.24298134 |
| 15 November 2026 |
Minimal surface area of an integer box with volume at least n in O(n^(1/6)) steps DOI: 10.5281/ZENODO.24242032 |
| 14 November 2026 |
Fewer multiplications for the least primitive root of every prime: a quadratic filter, character reuse and a splitting tree DOI: 10.5281/ZENODO.24219447 |
| 13 November 2026 |
Exact counting of cube-full numbers in time O(x^(1/5)): a convolution formula and new terms of the sequence A362973 DOI: 10.5281/ZENODO.24184449 |
| 12 November 2026 |
Distinct digits of integers in base 3 and in any base: closed forms, exact counting and an O(log N) algorithm for the sequence A043530 DOI: 10.5281/ZENODO.24151472 |
Mark Kim