OFFSET
1,3
LINKS
Antoine Mathys, Table of n, a(n) for n = 1..20000
EXAMPLE
For n=1, there is nothing to do. Hence a(1)=0.
For n=4, the possible sequences of steps are 4->3->2->1 and 4->2->1. Thus the minimal number of steps needed to reach 1 is a(4)=2.
For n=6, the possible sequences of steps are 6->5->4->3->2->1, 6->5->4->2->1 and 6->3->2->1. Thus the minimal number of steps needed to reach 1 is a(6)=3.
MATHEMATICA
divs[n_] := Append[Select[Most[Divisors[n]], #>= Sqrt[n] &], n-1]; a[0] = 0; a[1] = 0; a[n_] := a[n] = 1 + Min[a/@divs[n]]; Array[a, 100] (* Amiram Eldar, Nov 29 2018 *)
PROG
(C)
#include <stdio.h>
int main ()
{
const int N = 100;
int steps[N + 1];
steps[1] = 0;
for (int n = 2; n <= N; n++) {
int next = n - 1;
for (int i = n - 1; i * i >= n; i--) {
if (n % i == 0) {
if (steps[i] < steps[next]) {
next = i;
}
}
}
steps[n] = 1 + steps[next];
}
for (int n = 1; n <= N; n++) {
printf ("%d %d\n", n, steps[n]);
}
}
(PARI) seq(n)={my(v=vector(n)); for(n=2, n, my(m=v[n-1]); fordiv(n, d, if(d>=n/d && d<n, m=min(m, v[d]))); v[n]=m+1); v} \\ Andrew Howroyd, Nov 29 2018
CROSSREFS
KEYWORD
nonn
AUTHOR
Antoine Mathys, Nov 29 2018
STATUS
approved