login
The OEIS is supported by the many generous donors to the OEIS Foundation.

 


Minimal number of steps needed to get from n to 1, where for n > 1 the next step is to either n-1 or max(a,b) for any a > 1 and b > 1 such that ab=n.
1

%I #23 May 04 2019 14:01:51

%S 0,1,2,2,3,3,4,3,3,4,5,3,4,5,4,3,4,4,5,4,5,6,7,4,4,5,4,5,6,4,5,4,5,5,

%T 5,4,5,6,5,4,5,5,6,6,4,5,6,4,5,5,5,5,6,4,5,4,5,6,7,4,5,6,4,4,5,6,7,5,

%U 6,5,6,4,5,6,5,6,6,5,6,4,4,5,6,4,5,6,7

%N Minimal number of steps needed to get from n to 1, where for n > 1 the next step is to either n-1 or max(a,b) for any a > 1 and b > 1 such that ab=n.

%H Antoine Mathys, <a href="/A322163/b322163.txt">Table of n, a(n) for n = 1..20000</a>

%e For n=1, there is nothing to do. Hence a(1)=0.

%e 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.

%e 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.

%t 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 *)

%o (C)

%o #include <stdio.h>

%o int main ()

%o {

%o const int N = 100;

%o int steps[N + 1];

%o steps[1] = 0;

%o for (int n = 2; n <= N; n++) {

%o int next = n - 1;

%o for (int i = n - 1; i * i >= n; i--) {

%o if (n % i == 0) {

%o if (steps[i] < steps[next]) {

%o next = i;

%o }

%o }

%o }

%o steps[n] = 1 + steps[next];

%o }

%o for (int n = 1; n <= N; n++) {

%o printf ("%d %d\n", n, steps[n]);

%o }

%o }

%o (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

%K nonn

%O 1,3

%A _Antoine Mathys_, Nov 29 2018

Lookup | Welcome | Wiki | Register | Music | Plot 2 | Demos | Index | Browse | WebCam
Contribute new seq. or comment | Format | Style Sheet | Transforms | Superseeker | Recents
The OEIS Community | Maintained by The OEIS Foundation Inc.

License Agreements, Terms of Use, Privacy Policy. .

Last modified September 21 11:40 EDT 2024. Contains 376084 sequences. (Running on oeis4.)