A124202 a(n) = median of the largest prime dividing a random n-digit number.
3, 12, 53, 229, 947, 3863, 15731, 63823, 258737
Offset: 1
Examples
The largest prime divisors of the nonunit 1-digit numbers are 2, 3, 2, 5, 3, 7, 2 and 3 respectively, with median 3. Of the 90 2-digit numbers, there are 45 whose largest prime divisor is 11 or less and 45 whose largest prime divisor is 13 or greater, so any of 11, 12, or 13 could be used for the second term, although the arithmetic average of the endpoints is commonly used.
References
- D. E. Knuth, The Art of Computer Programming, Seminumerical Algorithms, Addison-Wesley, Reading, MA, 1969, Vol. 2.
Programs
-
GAUSS
n = 1; a = 2 | 3 | 2 | 5 | 3 | 7 | 2 | 3; meana = meanc(a); mediana = median(a); format /rdn 1,0; print n;; "-digit numbers:"; print " Median = ";; mediana; format /rdn 10,5; print " Mean = ";; meana; print; b = 1 | a; dim = 1; _01: wait; n = n+1; dim = 10*dim; a = b | zeros(9*dim,1); i = dim; do until i == 10*dim; if i == 2*floor(i/2); a[i] = a[i/2]; else; p = firstp(i); if p == i; a[i] = i; else; a[i] = a[i/p]; endif; endif; i = i+1; endo; b = a[dim:10*dim-1]; meana = meanc(b); mediana = median(b); format /rdn 1,0; print n;; "-digit numbers:"; print " Median = ";; mediana; format /rdn 10,5; print " Mean = ";; meana; print; b = a; goto _01; proc firstp(n); local i; i = 3; do until i > sqrt(n); if n == i*floor(n/i); retp(i); endif; i = i+2; endo; retp(n); endp;
-
MATLAB
P = primes(10^8); L = zeros(1,10^8); for p = P L([p:p:10^8]) = p; end A(1) = median(L(2:9)); for d = 2:8 A(d) = median(L(10^(d-1):10^d-1)); end A % Robert Israel, Dec 11 2015
-
Maple
seq(Statistics:-Median([seq(max(numtheory:-factorset(n)),n=10^(d-1)..10^d-1)]),d=1..7); # Robert Israel, Dec 11 2015
-
Mathematica
f[n_] := Block[{k = If[n == 1, 1, 0], lst = {}, pt = 10^(n - 1)}, While[k < 9*pt, AppendTo[lst, FactorInteger[pt + k][[ -1, 1]]]; k++ ]; Median@ lst]; (* Robert G. Wilson v, Dec 14 2006 *)
-
Python
from sympy import factorint from statistics import median def a(n): lb, ub = max(2, 10**(n-1)), 10**n return int(round(median([max(factorint(i)) for i in range(lb, ub)]))) print([a(n) for n in range(1, 6)]) # Michael S. Branicky, Mar 12 2021
Extensions
Edited by Robert G. Wilson v, Dec 14 2006
a(8) from Robert Israel, Dec 11 2015
a(9) from Giovanni Resta, Apr 19 2016
Comments