Publications
Research papers and technical notes on algorithms, computational mathematics and exact computation.
-
Let T(N) be the number of integer right triangles with perimeter at most N (A299706 for N=10^n). We prove the exact formula T(N) = sum_{r >= 1, r odd, squarefree} R(floor(floor(N/2)/r)), where R(M) = #{(a,b) in N^2 : a < b < 2a, ab <= M}, in which neither a coprimality condition nor a parity condition appears. The function R(M) reduces to a sum sum floor(M/a) over an interval of length ~ sqrt(M), and the dual form involves the counting function Q of odd squarefree integers. A Dirichlet hyperbola split gives an algorithm with O(N^{3/4}) operations. Replacing the sums of integer parts by a walk along the convex hull of the lattice points above the hyperbola (a descent in the Stern-Brocot tree with batched steps), and the evaluation of Q by blocks of equal floor(z/d^2), lowers the cost to O(N^{2/3} log^2 N) operations and O(N^{1/2}) memory, against Theta(N) for the enumeration of primitive triples used for the entry. The method reproduces the ten listed terms of A299706 and computes T(10^n) for n=11,...,17; for example T(10^{17}) = 258777325927633181. The C implementation evaluates T(10^{14}) in 8.2 s, against 35 s for the O(N^{3/4}) version, and T(10^{17}) in 863 s; the measured growth between 10^{14} and 10^{17} is N^{0.67}. The increments of T(10^n)/10^n agree with the constant ln(2)*ln(10)/pi^2 of the classical asymptotics T(N) ~ (ln(2)/pi^2)*N*ln(N) to 9 digits.
DOI: 10.5281/ZENODO.24298134 | pdf -
Let a(n) be the minimum of ab + bc + ca over positive integers a, b, c with abc >= n (half the minimal surface area of an integer box of volume at least n; OEIS A400004). Writing a box with sides a <= b <= c through the sum s = a + b + c and the two gaps y = b - a, w = c - b, the surface becomes ab + bc + ca = (s^2 - N)/3 with N = y^2 + yw + w^2 the Eisenstein norm, and 27*abc a cubic Phi(s,y,w) that is monotone in w. This reduces the search to at most three values of s and, for each, a single scan over y with a closed-form optimal w and an exact stopping rule. The algorithm is exhaustive, uses O(n^(1/6)) steps in the worst case, and needs about n^(1/9) steps on average in measurements up to n = 10^48. It computes a(10^45) in 0.6 s in Python. A second method, a scan over the smallest side with a closed-form inner minimum, is also O(n^(1/6)). The values a(10^k) are listed for k <= 48.
DOI: 10.5281/ZENODO.24242032 | pdf -
Let Q(x) be the number of squarefree integers n <= x (A071172 for x = 10^k). We prove that Q(x) = sum_{d <= D} mu(d)*floor(x/d^2) + sum_{t <= T} (M(y_t) - M(D)) with y_t = floor(sqrt(x/t)), T = floor(x/(D+1)^2) and M the Mertens function, that the set {y_t} is closed under y -> floor(y/k) in the sense floor(y_t/k) = y_{t*k^2}, and that all M(y_t) follow from a table of M up to D by a recursion. We reduce this recursion to integers coprime to a squarefree modulus W: M(y) = sum_{e | W} mu(e)*M_W(floor(y/e)) and sum_{(k,W)=1} M_W(floor(y/k)) = 1, with the large-k part evaluated over squarefree n coprime to W through counts of coprime integers. For W = 210 the number of steps is at most (64/105)*x*D^(-3/2) instead of (8/3)*x*D^(-3/2), and the sieve visits only the 48/210 of the integers coprime to 210. The total cost is O(x^(2/5) (log log x)^(3/5)). The floating-point division of the inner loops is proved exact for numerators below 2^53. The C implementation reproduces all 22 terms of A071172 listed in the data section of the entry, computes Q(10^22) in 3.5 s, Q(10^23) in 9.4 s and Q(10^24) = 607927101854026628773299 in 27.8 s on one core, against 51.7 s for Q(10^12) by the program of the entry.
DOI: 10.5281/ZENODO.24232426 | pdf -
For a prime p let g(p) and h(p) be the least primitive roots modulo p and modulo p^2. We give an exact algorithm that computes g(p) and decides g(p) = h(p) for every prime p with 3.5 times fewer modular multiplications per prime than the algorithm that tests each prime divisor q of p - 1 by its own exponentiation, and 2.5 to 3.2 times shorter running time for p < 2^32. The algorithm combines a table-driven quadratic filter, evaluation of composite candidates from the characters of their prime factors, a splitting tree that produces all values a^((p-1)/q) from one exponentiation chain, and, for p < 2^32, a fusion of the Wieferich test g^(p-1) != 1 (mod p^2) into the tree. For all primes 3 <= p < 2*10^9 it takes 56 s on one core and reproduces the 24 record values of g(p) and the only exception g(p) != h(p) in this range, p = 40487.
DOI: 10.5281/ZENODO.24219447 | pdf -
We compute g(p), the least positive primitive root of a prime p, for all primes p <= N. A segmented sieve factors p - 1 for every prime in a block. The quadratic character of each candidate is obtained from a table indexed by p mod 4g for g < 128 and by a Jacobi-symbol computation otherwise; perfect powers are skipped, and the remaining tests for odd prime divisors q of p - 1 are exponentiations that run 32 at a time in AVX2 lanes of 32-bit Montgomery arithmetic for p < 2^31, and by a divide-and-conquer descent with total exponent length at most (ceil(log_2 k) + 1) * log_2(p - 1) for k odd prime divisors for larger p. The cost is O(A(N) log N log log N) per prime, where A(N) is the mean of g(p) over p <= N. At N = 10^9 the C implementation takes 350 ns per prime on one core, 4.0 times less than the textbook test on the same sieved factorization, and at N = 10^8 it is 5.4 times faster than trial-division factoring (medians of three runs). A Python implementation is 3.2 times faster than SymPy at N = 10^6.
DOI: 10.5281/ZENODO.24207598 | pdf -
A positive integer is cube-full if p | n implies p^3 | n. Let N(x) be the number of cube-full integers n <= x (A362973 for x = 10^k). We prove that the Dirichlet series of the cube-full integers factors as zeta(3s)*zeta(4s)*zeta(5s)*R(s) with R(s) = prod_p (1 - p^(-8s) - p^(-9s) - p^(-10s) + p^(-13s) + p^(-14s)), and hence N(x) = sum_r rho(r) * T(floor(x/r)), T(y) = #{(a,b,c) in N^3 : a^3*b^4*c^5 <= y}, where r runs over the O(x^(1/8)) integers all of whose prime exponents lie in {8,9,10,13,14}. The count T(y) is computed in O(y^(1/5)) operations by a two-variable hyperbola split at y^(1/7). The total cost is O(x^(1/5)) arithmetic operations, against Theta(x^(1/4)) for the programs of the OEIS entry. The method reproduces the 32 listed terms and computes the terms for k = 32,...,38 (k = 32,...,36 extend the data section of the entry, k = 37,38 lie beyond its linked table of k <= 36); N(10^38) = 21607893735561 takes 180 s in C. At x = 10^26 the program of the entry takes 58.6 s, ours 2.26 s in Python and 0.61 s in C.
DOI: 10.5281/ZENODO.24184449 | pdf -
Let a_b(n) be the number of distinct digits of n in base b; a_3 is A043530. We prove that a_3 is 3-automatic with a 7-letter morphism. For every base b >= 2 we count the m-digit integers with exactly j distinct digits in closed form through the surjection numbers sigma_{m,j} = j! * S(m,j), N_m(j) = binomial(b-1, j)*sigma_{m,j} + binomial(b-1, j-1)*(sigma_{m,j} - sigma_{m-1,j} - sigma_{m-1,j-1}), with N_m(2) = 2^(m+1) - 4 and N_m(3) = 2*3^(m-1) - 2^(m+1) + 2 in base 3. The sum of a_b over the integers with m digits is (b-1)*(b^m - (b-1)^m), whence sum_{n < 3^k} a_3(n) = 3^(k+1) - 2^(k+2) + 1. For arbitrary N we compute #{n <= N : a_b(n) = j} in O(b log_b N) arithmetic operations and sum_{n <= N} a_b(n) by a direct formula through the integers that miss a given digit in O(b log_b N) operations without binomial coefficients; the n-th integer with at most j distinct digits is found in O(b log n) steps. The number of n <= x with fewer than three ternary digits lies between 2*x^(log_3 2) - 2*log_3(x) - 4 and 8*x^(log_3 2). The sum sum_{n <= 10^1000} a_3(n) takes 6.4 ms; the table of a_3(n) for n < 3^18 is built in 0.51 s in C and 2.9 s in NumPy, against 1.26 s for 1.6*10^6 terms by the definition in a Python loop.
DOI: 10.5281/ZENODO.24151472 | pdf -
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.
DOI: 10.5281/ZENODO.24109380 | pdf -
Let a(1)=1 and a(m+1)=a(m)/m if m divides a(m), and a(m+1)=m*a(m) otherwise (OEIS A008336). We prove the product identity a(n) = (n-1)! / product_{m<n, m divides a(m)} m^2, establish an exact recursion on the prime exponents that decides the divisibility condition m divides a(m), and show that the exponent of a prime p > sqrt(n) behaves as a ballot-type walk with fixed parity. The exponent recursion yields the exact prime factorization of a(n) in O(n log log n) arithmetic operations using O(n) memory, completely outperforming the traditional big-integer iteration which requires Omega(n^2 / log n) word operations. Since a(n) >= product_{n/2<p<n} p, the number a(n) has at least (1/(2 ln 2) + o(1)) * n bits. Therefore, any algorithm that outputs a(n) in binary requires Omega(n / log n) steps. This proves that the proposed exponent framework is optimal up to a minor factor of O(log n log log n), and no algorithm can evaluate a(n) in o(n / log n) steps. All theoretical claims are rigorously proved. In C, the compact implementation computes the complete factorization of the monster term a(10^9) in 55.9 seconds using 2 GB of memory. On smaller scales (n=10^5), the exponent framework runs 17 times faster than big-integer iteration in Python and approximately 500 times faster in C.
DOI: 10.5281/ZENODO.24085265 -
Let a(m) be the number of abelian groups of order m (A000688) and A(n) = sum_{m<=n} a(m) (A063966). The Dirichlet series of a is product_{k>=1} zeta(ks) = zeta(s) * zeta(2s) * product_{k>=3} zeta(ks). The last factor is the series of a function g supported on cube-full integers, which gives the exact identity A(n) = sum_{t<=n} g(t) * D([n/t]) with D(y) = sum_{a>=1} [y/a^2], summed over the O(n^(1/3)) cube-full integers t. Each D(y) is computed in O(y^(1/3)) operations, or read from a table of size O(n^(1/3)). The total cost is O(n^(1/3) log n) operations on O(log n)-bit integers and O(n^(1/3)) memory, against Theta(n^(1/2)) for the powerful-number method and Theta(n log log n) for sieving. All claims are proved. On one core, A(10^12) takes 0.919 s with the powerful-number method and 0.025 s with the new method in Python (36.8 times faster); A(10^18) takes 2.705 s in Python and 0.297 s in C, and A(10^19) = 22948565870634163153 takes 0.655 s in C. The values for n = 10^6, ..., 10^19 are tabulated; the OEIS table stops at n = 10^4.
DOI: 10.5281/ZENODO.24062569 -
Let N_k(N) be the number of points of Z^k with squared norm at most N. The OEIS sequences A055412 and A055414 are a(n)=N_k(n^2) for k=6 and $k=8$. The numbers r_6(m) and r_8(m) of representations of m as a sum of six and eight squares are divisor sums (Glaisher).
DOI: 10.5281/ZENODO.24050631
We prove that N_6(N) and N_8(N) are explicit combinations of the hyperbola sums sum_{d<=N} d^2 * c([N/d]), sum_{d<=N} chi(d) * d^2 * [N/d] and sum_{d<=X} d^3 * [X/d], where chi is the non-principal character modulo 4 and c is the indicator of m mod 4 in {1,2}. Each value is computed exactly with at most 4.5 * sqrt N blocks of constant quotient, that is O(n) operations for a(n), while the Python program of A055412 factors all m <= n^2 and the C++ program of its table costs Theta(R^3) for all terms up to R.
The formulas reproduce all published terms. At n=1000 the Python program of A055412 takes 11.4 s and the formula 0.0057 s (0.00049 s in C); a(n) for n=10^8 takes 43.6 s in C for k=6. -
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.
DOI: 10.5281/ZENODO.24009232 -
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.
DOI: 10.5281/ZENODO.23969822 -
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.
DOI: 10.5281/ZENODO.23931336
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. -
For an integer p >= 2, let S_p(n) be the summatory function of floor(n/k^p) over k >= 1, which counts the number of integer pairs (j,k) with j * k^p <= n. The case p=2 corresponds to the OEIS sequence A013936, and p=3 corresponds to A013937. Traditional formulas listed in the OEIS require O(n^(1/p)) operations, and classical Dirichlet hyperbola-type grouping partitions the domain into O(n^(1/(p+1))) terms.
DOI: 10.5281/ZENODO.23853948
We prove an exact structural decomposition identity that evaluates S_p(n) in O(n^(1/(p+2)) log n) arithmetic operations on integers of O(log n) bits, establishing the first method to break the O(n^(1/(p+1))) hyperbola barrier. The tail of the sum is represented as a lattice point count of a convex region bounded by the curve y = (n+1)/x^p in a bounded box. We implement a deterministic lower convex hull walk driven by exact integer predicates, counting the encapsulated lattice points via Pick's theorem and bounding the total number of hull vertices via Andrews' theorem on convex lattice polygons.
The framework is verified against direct enumeration and baseline grouping methods up to n=10^28. In Python 3.12, the sublinear algorithm evaluates the exact value of S_2(10^26) in 109 s (improving upon the 190 s grouping baseline) and S_3(10^30) in 14 s (against 104 s for grouping). The full source code and cross-verification logs are provided. -
Let N(M) be the number of integer pairs (x,y) with x^2+xy+y^2 <= M, representing the number of points of the planar hexagonal lattice A_2 inside a closed disc of squared radius M. This arithmetic function determines the OEIS sequences A038589, A014201, and A307109, which are traditionally computed using double loops or character sum enumerations requiring O(M) or O(sqrt(M)) operations.
DOI: 10.5281/ZENODO.23830915
We prove a rigorous 12-fold sector decomposition identity that reduces the evaluation of N(M) to an isolated monotone sum S over a single unique arc of the underlying ellipse where the absolute slope is bounded between 1/2 and 1. We derive an exact, deterministic sublinear algorithm to compute S by executing a fast walk along the upper convex hull of the lattice points. The Stern-Brocot descent step is tracked analytically using a convex quadratic characterization of the principal norm form x^2+xy+y^2, bounding intermediate steps via an exact integer square root.
The developed algorithm achieves the exact count in O(M^(1/3) log M) operations, requiring only 0.78 * M^(1/3) iterations, which was verified numerically up to M=10^20. In Python 3.12, computing N(10^20 + 12345) takes 11.2 s, while smaller scales such as M=10^16 take 0.46 s, improving upon the vectorized Dirichlet character sum baseline by several orders of magnitude. The full source code and cross-verification logs are provided. -
Let N(M) be the number of lattice points inside the closed disc x^2+y^2 <= M (OEIS A057655). The classic sequences A000328 and A000603 represent N(n^2) and the number of non-negative solutions respectively, traditionally computed via direct column summation in O(sqrt(M)) steps.
DOI: 10.5281/ZENODO.23835768
We present a modified Stern-Brocot hull walk algorithm that evaluates N(M) exactly by following the upper convex hull of the lattice points of the disc. Unlike traditional implementations that carry a continuous stack of ancestors, our descent is completely restarted at every hull vertex from the basis vectors (1,1) and (1,0). Every run of the descent is computed in closed form: the longest run of one kind is extracted as the integer root of a quadratic norm form, and the shortest run of the other kind is obtained as the minimum of a convex quadratic. We prove that the sum of the abscissas of the two current Stern-Brocot vectors at least doubles in every round of the descent, bounding the number of rounds per vertex by log_2(2x_0) + 2. Incorporating Andrews' theorem on the number of vertices, we provide the first complete proof that the entire evaluation terminates in O(M^(1/3) log^2 M) exact arithmetic operations.
The framework is verified numerically against independent stack-based baselines up to M=10^18. In Python 3.12, the classical Gauss constant A000328(10^9) is computed in 7.8 s, and A000328(10^10) is returned in 49 s. The full source code is publicly available. -
Let a(n) be the number of triples of positive integers (x,y,r) such that xy <= n, r divides xy, and r divides x or y (OEIS A268756). The original entry in the OEIS provides only an enumeration program of cost O(n^2). We establish an exact combinatorial identity a(n) = 2*D_3(n) - T(n), where D_3(n) is the summatory function of d_3(k) (OEIS A061201) and T(n) is the sum of d(gcd(x,y)) over xy <= n (OEIS A268732). Equivalently, the Dirichlet generating series of the increments is proved to be zeta(s)^2 * (2*zeta(s) - zeta(2s)).
DOI: 10.5281/ZENODO.23831138
Using these structural properties, we derive a precise second-order asymptotic expansion a(n) = n * (ln^2 n + c_1 * ln n + c_0) + O(n^(1/2+epsilon)), where the constants c_1 = -0.18164... and c_0 = 2.59373... are explicitly evaluated using Euler's constant, the first Stieltjes constant gamma_1, and the derivative zeta'(2).
Furthermore, we develop an exact sublinear algorithm that computes a(n) using a prefix table of the divisor function D(x) and a modified Dirichlet hyperbola method in O(n^(2/3) log n) arithmetic operations and O(n^(2/3)) memory. The algorithm matches the known terms and has been validated against independent sieves up to n=10^7. In Python 3.12, the value a(10^12) = 761,048,161,394,384 is returned in 3.4 s, and a(10^13) is computed in 22.6 s. -
Let a(n) be the number of pairs 1 <= x <= y <= n-1 with gcd(x,n) = gcd(y,n) = gcd(x+y,n) = 1 and 1/x + 1/y = 1/(x+y) mod n, corresponding to the OEIS sequence A376202. The original entry contains an enumeration program of cost O(n^2) and several unproved observations.
DOI: 10.5281/ZENODO.23763532
This paper shows that the condition is equivalent to the quadratic congruence x^2 + xy + y^2 = 0 mod n. We prove a closed formula: a(n) = 0.5 * phi(n) * rho(n) for n >= 2, n != 3, and a(3) = 2, where phi(n) is Euler's totient function and rho(n) is the number of roots of t^2 + t + 1 mod n. This formula completely determines a(n) from the prime factorization of n, proving the conjectures about zeros and cuban primes (A007645) listed in the OEIS entry.
For the partial sums S(N) = sum_{n<=N} a(n), we establish an exact sublinear algorithm using a Min_25-type sieve that runs in O(N^(3/4) / log N) operations. We also prove an asymptotic formula S(N) = c * N^2 + O(N^(3/2+eps)) with an explicit constant c = 0.0792641301...
In Python 3.12, computing the partial sum S(10^10) = 7,926,412,625,957,303,606 takes 19.7 s, and a single large term like a(10^15 + 3) takes just 0.57 s. -
Let P(M) be the number of pairs (x, y) in Z^2 with gcd(x, y) = 1 and x^2 + y^2 <= M. This paper addresses three related OEIS sequences: A304651 (which is P(n)), A175341 (which is P(n^2)), and A124254 (which counts coprime pairs 1 <= x <= y with x^2 + y^2 < n^2). The current OEIS implementations rely on O(M) or O(n^2) recurrences, or brute-force enumeration.
DOI: 10.5281/ZENODO.23764050
We prove the exact Möbius inversion formula P(M) = 4 * sum_{k <= sqrt(M)} mu(k) * G(floor(M / k^2)), where G(q) counts the lattice points (x, y) with x >= 1, y >= 0, and x^2 + y^2 <= q. We establish the explicit identities A175341(n) = P(n^2) and A124254(n) = P(n^2 - 1) / 8 for n >= 2, proving the combinatorial conjecture regarding the forest-and-trees problem in A124254.
Furthermore, we present an algorithm that evaluates P(M) in O(sqrt(M) * log M) vectorized operations using O(sqrt(M)) memory. The approach utilizes a segmented Möbius sieve, prefix sums of the Möbius function, a small-argument table for G(q), and a fast sublinear convex hull walk for large arguments.
The formula has been numerically verified against all published terms and independent GCD counts up to M = 10^8. In Python 3.12, computing P(10^8) = 190,985,984 takes just 0.0025 s, P(10^14) takes 1.5 s, and A175341(3 * 10^7) = 1,718,873,385,377,192 is computed in 4.5 s. -
Let a(n) be the number of pairs of non-negative integers (x, y) satisfying x^2 + 2*y^2 <= n^2, corresponding to the OEIS sequence A218706. The current entry provides enumeration programs and a column sum costing O(n) integer square roots.
DOI: 10.5281/ZENODO.23764391
This paper generalizes the problem to diagonal quadratic forms w_x * x^2 + w_y * y^2 <= M for positive integers w_x, w_y and M >= 0. We prove that the number of points with x, y >= 1 equals A_x + A_y - X_0 * Y_0, where A_x and A_y are column and row sums over the boundary split by the point of slope -1 (with coordinates X_0, Y_0). Each sum is evaluated by a sublinear walk along the upper convex hull of the lattice points in the ellipse, where every step uses exact integer arithmetic. The Stern-Brocot descent step is solved in closed form via a convex quadratic in one integer variable.
The method covers both A218706 and the classic Gauss circle sequence A000603 as special cases. The algorithm requires approximately 2 * M^(1/3) iterations, verified numerically against all published terms and independent counts up to M = 10^11. In Python 3.12, the value a(10^9) = 555,360,368,123,355,523 is computed in 9.6 s, and a(10^10) takes 50.8 s, significantly outperforming standard O(n) approaches. -
Lattice Points in the Astroid: An Exact Integer Test and a Convex Hull Walk for the Sequence A216877
Let a(n) be the number of integer points (x, y) with |x|^(2/3) + |y|^(2/3) <= n^(2/3), corresponding to the OEIS sequence A216877. The original entry contains only a brute-force program of cost O(n^2). This paper provides an exact integer criterion for membership, proving that for integers x, y >= 1 the inequality holds if and only if n^2 - x^2 - y^2 >= 0 and (n^2 - x^2 - y^2)^3 >= 27 * x^2 * y^2 * n^2.
DOI: 10.5281/ZENODO.23763335
Using this exact test and algebraic symmetry, the total count a(n) is reduced to a single monotone sum S over the boundary. We compute S by a walk along the lower convex hull of the lattice points above the curve, where every decision is an exact integer comparison. The Stern-Brocot descent step is solved in closed form by using the tangent point of the astroid.
The algorithm requires approximately 1.04 * n^(2/3) iterations, verified numerically up to n = 10^10. In Python 3.12, the value a(10^9) = 1,178,097,245,096,271,057 is computed in 5.4 s, and a(10^10) takes 29 s, presenting a significant speedup over standard O(n) column-counting approaches (8.0 s for n = 10^6). -
Let a(n) be the number of pairs (x,y) in {0, ..., n-1}^2 such that x^2+y^2 divides n (OEIS A239680). The original OEIS entry contains only a brute-force program of cost O(n^2). We prove an exact multiplicative formula a(n) = h(n) + s(n) - 2*[n=1], where h = 1*1*chi_4 is a Dirichlet convolution with h(2^e) = e+1, h(p^e) = binomial(e+2, 2) for p = 1 mod 4, h(p^e) = floor(e/2)+1 for p = 3 mod 4, and s(n) is the number of square divisors of n. Equivalently, the Dirichlet generating series of a(n) is established as zeta(z)^2 * L(z, chi_4) + zeta(z)*zeta(2z) - 2.
DOI: 10.5281/ZENODO.23721505
For the partial sums S(N) = sum_{n<=N} a(n), we prove the exact reduction to the Gauss circle problem: S(N) = sum_{k=1}^N G(floor(N/k)) + sum_{m>=1} floor(N/m^2) - 2, where G(M) counts the lattice points inside a closed quadrant disc x^2+y^2<=M.
By replacing the traditional direct evaluation of G(M) with a sublinear walk along the convex hull of the lattice points of the disc (a Stern-Brocot descent with an exact quadratic step), the algorithm evaluates G(M) in approximately 1.13 * M^(1/3) iterations, verified numerically up to M=10^18. In Python 3.12, the sum S(10^11) = 2,185,202,802,637 is computed in 1.5 s, G(10^18) in 3.1 s, and a single term a(10^15+7) takes 0.06 s. -
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.
DOI: 10.5281/ZENODO.23662114
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. -
Let T(n) be the set of integer-sided triangles with perimeter n. For an arithmetic property f and a choice of the smallest, middle or largest side, let S(n) be the number of triangles in T(n) whose chosen side k has f(k)=1. The OEIS contains several such sequences, all defined by double sums with O(n^2) terms: A308453, A308455 and A308454 (the smallest, middle or largest side is squarefree) and A308202 and A308209 (the smallest or largest side is coprime to n).
DOI: 10.5281/ZENODO.23646199
We prove that the number W_n(k) of triangles of perimeter n whose chosen side equals k is, for each of the three choices, an affine function of k on at most two intervals and two residue classes modulo 2, with explicit coefficients. Since the parity of k enters the weights only through the intercepts, S(n) is a combination, with explicit rational coefficients, of differences of three prefix functions at at most four points: the counts over even and odd k, and the first moment sum of k*f(k). For squarefree sides these prefix sums are evaluated by the identity mu^2(k) in O(sqrt(n)) arithmetic operations; for sides coprime to n they are evaluated in O(2^omega(n)) arithmetic operations once n is factored.
The Python 3.12 implementation agrees with the OEIS data (70-72 terms each). A308453 is computed for n=10^13 in 1.7 s (the double sum needs 3.4 s already at n=10^4), and A308202 for n=10^24+7 in 0.34 ms. -
Let a(n) be the number of integer-sided triangles with perimeter n whose smallest side divides the largest side (OEIS A308166). The only formula listed in the OEIS is a double sum requiring O(n^2) operations. We prove the exact identity a(n) = [3|n] + m - floor(m/2) + floor(m/3) + 2*D(floor(m/2)) - D(m), where m = n - 1 and D(x) is the divisor summatory function (OEIS A006218). This reduces the evaluation of a(n) to two values of D(x), achieving O(sqrt(n)) complexity via the Dirichlet hyperbola method and O(n^(1/3)) via a Stern-Brocot hull-walk kernel. We derive the asymptotic behavior a(n) = (5/6 - ln 2)*n + O(sqrt(n)). Python 3.12 implementations agree with benchmarks up to n = 10^18. The exact values of a(10^k) for k <= 18 are provided.
DOI: 10.5281/ZENODO.23610818 -
Let sigma(k) be the sum of divisors of k and S(n) be the summatory divisor-sum function, defined as the sum of k * floor(n/k) for k from 1 to n (OEIS A024916). Standard algorithms evaluate isolated values of S(n) using the Dirichlet hyperbola method in O(sqrt(n)) operations. This paper extends the Stern-Brocot walk along the lower convex hull of lattice points above the hyperbola uv = n to higher moments. Along every hull edge, the sums of q, yq, and q^2 (where q = floor(n/y)) are obtained in closed form from three floor sums of a primitive step, computed once per edge direction via a Euclid-type recursion in O(log n) steps.
DOI: 10.5281/ZENODO.23615983
This simultaneously returns D(n) and S(n) in O(n^(1/3)) operations, yielding the first sublinear algorithm for this sequence. It also computes the sum of remainders (OEIS A004125) and the sum of squared quotients. The Python 3.12 implementation is verified against brute force and baseline evaluations up to n = 10^18. The exact values of S(10^k) for k <= 18 are provided. -
This paper considers the exact computation of the number of primitive Q(N) and all T(N) integer-sided triangles with a 120-degree angle and perimeter at most N. Standard methods scale linearly with O(N) complexity. We show that primitive triangles correspond one-to-one to pairs (x,y) satisfying 3x < 2y < 4x, gcd(x,y)=1, and 3 does not divide y, where the perimeter equals the product xy. The problem is thus reduced to evaluating a wedge-shaped hyperbolic sum under xy <= Z. By splitting the summation at a threshold of Z^(1/3) and removing the coprimality condition via Möbius inversion over integers coprime to 3, we obtain an O(sqrt(N) log N) algorithm for Q(N) and an O(N^(2/3)) algorithm for T(N). We derive the exact asymptotic density for primitive partitions as 9*ln(4/3)/(4*pi^2) * N. Python 3.12 implementations demonstrate substantial speedups against linear baselines, enabling the calculation of exact counts up to N = 10^16 for Q(N) and N = 10^13 for T(N).
DOI: 10.5281/ZENODO.23561814 -
The number of Pythagorean triangles (x,y,z) with legs x<y<=N is considered, both primitive ones, Q(N), and all of them, . The OEIS lists the values for N=10^{n} up to n=11 (sequences A239581, A239744, A239786). It is shown that the plane of Euclid pairs (m,n) is split by the ray m=(1+sqrt2)n into two parts, in each of which the larger leg is given by a hyperbola in its own coordinates: mn<=Y/2 and uv<=Y with u=m-n, v=m+n. The boundary between the parts is counted exactly by Beatty sums with a 40-digit approximation of sqrt2; coprimality is removed with the Mobius function; for all triangles the hyperbolic sum is split at a threshold into a table of small legs and a sum over the number of multiples. The result is an O(sqrt(N) log N) algorithm for Q(N) and an O(N^{2/3}) algorithm for T(N). All 11 known terms of the three sequences are reproduced. Q(10^{11}) is computed in 0.75 s and T(10^{11}) in 22 s. New terms are computed: A239581 for n=12,...,17 (a(17)=17860363013590019 in 31 s); A239744 and A239786 for n=12 (4737245246856 and 4737245246845) and n=13 (51484953017395 and 51484953017383).
DOI: 10.5281/ZENODO.23518201 -
This paper considers the exact number of integer-sided triangles with perimeter p that are acute, right or obtuse. The formulas listed in the OEIS for these counts use double sums, requiring O(p^2) operations, and a single sum over the shortest side gives O(p). It is shown that, with u=p-a and v=p-b for the two shorter sides a <= b, the type of the triangle is decided by the sign of 2uv-p^2, so the acute triangles are the lattice points of a polygon lying under the hyperbola uv=p^2/2. The count reduces to one hyperbolic sum over a band of ratio sqrt(2), a few closed-form sums, and the number of divisor pairs of p^2/2 for the right triangles. With a hull-walk kernel for hyperbolic sums, this gives O(p^(2/3)) operations. The Python 3.12 implementation coincided with direct enumeration and baseline evaluations. At p=10^9+7 the linear method took 319.6 s, while the new method took only 3.2 s (100x speedup), enabling exact partition counts up to p=10^11+7.
DOI: 10.5281/ZENODO.23473044 -
This paper addresses the acceleration of computing arbitrary hexadecimal digits of pi using Bellard's formula. We propose a computational modification in which seven fractions with linear denominators are combined into a single rational function with a common denominator. This replacement reduces the number of modular exponentiations from seven to one for each term of the series. The mathematical basis of the transformation, the digit extraction algorithm, and integer arithmetic constraints are described. Local benchmarks in Python 3.12.6 demonstrate a runtime advantage of 1.93x to 2.72x over the standard implementation. Furthermore, the applicability of this fraction grouping method is investigated and successfully verified against Smith's formula.
DOI: 10.5281/zenodo.23348803 -
Finding integer relations is an important problem in computational mathematics. Given a set of real numbers, the task is to determine whether there exist small integer coefficients such that their linear combination equals zero. This paper presents APS (Adaptive Precision Search), an algorithm that uses an integer lattice embedding and LLL reduction to generate candidate integer relations. Unlike a single, direct application of LLL, APS uses several levels of computational precision. At each level, an integer lattice is constructed, LLL reduction is performed to obtain a transformation matrix, and candidates are extracted from that matrix. The original real-valued residual is computed for each candidate. Candidates that remain stable as precision increases are preferred over accidental approximate relations. In the experiments conducted, APS successfully recovered the prescribed relations in dimensions ranging from 4 to 30. At higher dimensions, a substantial runtime advantage over PSLQ was observed. In a dimension-30 test with a coefficient bound of 10, APS ran in approximately 0.027 seconds, whereas the PSLQ implementation used took approximately 6.41 seconds, achieving a speedup of approximately 258x.
DOI: 10.5281/zenodo.23270986 -
This paper considers the exact computation of the number R(n) of right triangles with vertices at the nodes of an n x n grid (sequence A077435 in the OEIS). A formula is obtained in the form of a fourfold sum, R(n) = 4S^2 + 4W, over p,q,g,mu >= 1 with gcd(p,q)=1. The summand is symmetric under the exchange of the pairs (g,mu) and (p,q); from this an algorithm of complexity O(n^(3/2+eps)) is derived. Next, the coprimality condition is removed by means of the Mobius function, the sum is split into layers, and the remaining two-dimensional sums over polygons are computed by a kernel of floor sums with moments in O(log n); the overall complexity is O(n log^2 n) arithmetic operations. Both Python implementations coincided with direct enumeration for n <= 7, with all OEIS values for n <= 35, and with the OEIS b-file up to n=10,000. In the measurements, the near-linear algorithm turned out to be faster at n=12,800 (9.35 s versus 11.55 s), yielding the previously unknown exact value of R(12800).
DOI: 10.5281/zenodo.23439957 -
This paper considers the exact evaluation of the arithmetic sum of products of integer quotients G(N) for a positive integer parameter N. We propose and investigate an implementation called QSS (Quotient-Split Summation), which combines direct evaluation of an initial segment with block grouping of indices by equal values of the first integer quotient. For each block, we prove that the second quotient takes at most two distinct consecutive values, allowing the block contribution to be computed analytically using a small, constant number of arithmetic operations. In the standard arithmetic-operation model, the algorithm performs O(sqrt(N)) iterations and returns the exact integer result. In local Python measurements, QSS was approximately 27.57 to 2406.83 times faster than direct enumeration for the tested sizes N = 10^4 to 10^8. Compared with two alternative sublinear quotient-grouping implementations, the measured advantage was approximately 1.67 to 2.01 times due to reduced constant overhead. These results apply to the specific software implementations and computer configuration tested and do not, by themselves, establish superiority over all existing algorithms.
DOI: 10.5281/zenodo.23286085 -
This paper addresses the computation of the alternating sum of squared binomial coefficients weighted by powers of integer indices. We describe an efficient exact method based on the derivatives of a finite hypergeometric polynomial and Stirling numbers of the second kind. A two-step recurrence relation for the derivatives at x = 1 is derived from the underlying differential equation. The proposed algorithm reduces the number of required arithmetic operations significantly compared to both direct summation and the previously known Kravchuk polynomial approach. Local benchmarking results demonstrate a substantial runtime advantage, achieving a speedup of up to 1062x in high-dimensional tests.
DOI: 10.5281/zenodo.23271148 -
This paper addresses the problem of exactly computing the number of quotient collisions E(N), defined as the number of index pairs i < j for which the integer parts of N/i and N/j coincide, as well as computing the exact distribution of quotient block sizes. The standard approach requires iterating over approximately sqrt(N) blocks. We propose a novel sublinear algorithm based on two key structural observations: the block size c_w takes one of two adjacent values m or m+1, where m = floor(N/(w(w+1))), and the sum of block sizes over an interval of constant m can be evaluated telescopically using only two values of the integer part. This allows evaluating the contribution of an entire interval in O(1) arithmetic operations, reducing the number of processed intervals to at most 2*ceil(N^(1/3)). We present the mathematical foundations, the algorithmic implementation, complexity bounds, and verification procedures. Empirical benchmarks in Python demonstrate a practical speedup ranging from 1.21x to 51.33x for N between 10^6 and 10^16, with the performance gain increasing asymptotically with N.
DOI: 10.5281/zenodo.23385618
Mark Kim