Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
a(n) is the greatest sum of the digital roots of the individual factorizations of n.
0

%I #66 Jun 09 2022 14:43:39

%S 1,2,3,4,5,6,7,8,9,7,2,8,4,9,8,10,8,11,1,9,10,4,5,11,10,8,12,11,2,11,

%T 4,12,6,10,12,13,1,3,7,13,5,13,7,8,14,7,2,14,14,12,11,10,8,15,7,15,4,

%U 4,5,13,7,8,16,16,9,8,4,12,8,14,8,17,1,3,13,5,9,11,7,15,18,7,2,15,13,9,6,10,8,16,11,9

%N a(n) is the greatest sum of the digital roots of the individual factorizations of n.

%H Project Euler, <a href="https://projecteuler.net/problem=159">Digital root sums of factorisations, Problem 159</a>.

%e a(24) = 11:

%e Factorization Sum of Digital Roots

%e 2 * 2 * 2 * 3 2 + 2 + 2 + 3 = 9

%e 2 * 3 * 4 2 + 3 + 4 = 9

%e 2 * 2 * 6 2 + 2 + 6 = 10

%e 4 * 6 4 + 6 = 10

%e 3 * 8 3 + 8 = 11

%e 2 * 12 2 + 1 + 2 = 5

%e 24 2 + 4 = 6

%e Result is 11.

%o (PARI) fcnt(n, m) = {my(d = divisors(n), v = List(select(x->((x>1) && (x<=m)), d)), list = List()); for (k=1, #v, my(x = fcnt(n/v[k], v[k])); if (#x==0, listput(list, [v[k]]), for (j=1, #x, listput(list, concat(v[k], x[j]))));); list;}

%o factoriz(n) = {if (n==1, return ([[1]])); my(list = fcnt(n, n), res = List()); for (i=1, #list, my(vi=list[i]); if (vecprod(vi) == n, listput(res, vi));); Vec(res);} \\ A162247

%o a(n) = {my(v = factoriz(n)); vecmax(vector(#v, k, vecsum(apply(x->(x-1)%9+1, v[k]))));} \\ _Michel Marcus_, Jun 06 2022

%o (Python)

%o def drs(x, m):

%o if x == 0:

%o return 0

%o return ((x - 1) % m) + 1

%o def a(n):

%o DRS = [drs(x, 9) for x in range(0, n + 1)]

%o for a in range(2, n):

%o da = DRS[a]

%o for b in range(2, 1 + (n // a)):

%o ab = a * b

%o if ab > n:

%o break

%o else:

%o x = da + DRS[b]

%o if DRS[ab] < x:

%o DRS[ab] = x

%o return DRS[1: n + 1][-1]

%Y Cf. A007953, A001055, A162247.

%K nonn,base

%O 1,2

%A _DarĂ­o Clavijo_, May 02 2022