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

 

Logo
Hints
(Greetings from The On-Line Encyclopedia of Integer Sequences!)
A317447 Number of permutations of [n] whose lengths of increasing runs are distinct prime numbers. 6

%I #11 Mar 29 2021 08:00:56

%S 1,0,1,1,0,19,0,41,110,70,13696,1,44796,155,411064,2122802,251746,

%T 1057634441,4404368,25043183,44848672,19725545894,106293316,

%U 307873058001,50194102,8305023165502,65808841818130,33715371370134,115625740201672616,78940089764191

%N Number of permutations of [n] whose lengths of increasing runs are distinct prime numbers.

%H Alois P. Heinz, <a href="/A317447/b317447.txt">Table of n, a(n) for n = 0..100</a>

%p g:= (n, s)-> `if`(n in s or not (n=0 or isprime(n)), 0, 1):

%p b:= proc(u, o, t, s) option remember; `if`(u+o=0, g(t, s),

%p `if`(g(t, s)=1, add(b(u-j, o+j-1, 1, s union {t})

%p , j=1..u), 0)+ add(b(u+j-1, o-j, t+1, s), j=1..o))

%p end:

%p a:= n-> b(n, 0$2, {}):

%p seq(a(n), n=0..40);

%t g[n_, s_] := If[MemberQ[s, n] || Not [n == 0 || PrimeQ[n]], 0, 1];

%t b[u_, o_, t_, s_] := b[u, o, t, s] = If[u + o == 0, g[t, s],

%t If[g[t, s] == 1, Sum[b[u - j, o + j - 1, 1, s ~Union~ {t}],

%t {j, 1, u}], 0] + Sum[b[u + j - 1, o - j, t + 1, s], {j, 1, o}]];

%t a[n_] := b[n, 0, 0, {}];

%t a /@ Range[0, 40] (* _Jean-François Alcover_, Mar 29 2021, after _Alois P. Heinz_ *)

%o (Python)

%o from functools import lru_cache

%o from sympy import isprime

%o def g(n, s): return int((n == 0 or isprime(n)) and not n in s)

%o @lru_cache(maxsize=None)

%o def b(u, o, t, s):

%o if u + o == 0: return g(t, s)

%o c1 = sum(b(u-j, o+j-1, 1, tuple(sorted(s+(t,)))) for j in range(1, u+1)) if g(t, s) else 0

%o return c1 + sum(b(u+j-1, o-j, t+1, s) for j in range(1, o+1))

%o def a(n): return b(n, 0, 0, tuple())

%o print([a(n) for n in range(41)]) # _Michael S. Branicky_, Mar 29 2021 after _Alois P. Heinz_

%Y Cf. A000040, A317131, A317444, A317445, A317446, A317448.

%K nonn

%O 0,6

%A _Alois P. Heinz_, Jul 28 2018

Lookup | Welcome | Wiki | Register | Music | Plot 2 | Demos | Index | Browse | More | 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 May 8 19:26 EDT 2024. Contains 372341 sequences. (Running on oeis4.)