OFFSET
0,5
EXAMPLE
1 is not a prime,
1 + 3 is not a prime,
1 + 3 + 2 is not a prime,
1 + 3 + 2 + 4 is not a prime.
So [1, 3, 2, 4] satisfies all the conditions.
---------------------------------------------
a(1) = 1: [[1]];
a(3) = 1: [[1, 3, 2]];
a(4) = 3: [[1, 3, 2, 4], [1, 3, 4, 2], [4, 2, 3, 1]];
a(5) = 8: [[1, 3, 2, 4, 5], [1, 3, 4, 2, 5], [1, 5, 2, 4, 3], [1, 5, 4, 2, 3], [4, 2, 3, 1, 5], [4, 2, 3, 5, 1], [4, 5, 1, 2, 3], [4, 5, 3, 2, 1]].
MATHEMATICA
Table[Count[Permutations@ Range@ n, _?(AllTrue[Accumulate@ #, ! PrimeQ@ # &] &)], {n, 0, 10}] (* Michael De Vlieger, Aug 26 2017 *)
PROG
(Python)
from functools import cache
from sympy import primerange
def a(n):
@cache
def c(t, s): # count satisfying permutations where items in t must be placed and sum is s
if s in primes: return 0
if len(t) == 0: return 1
S = set(t)
return sum(c(tuple(sorted(S-{i})), s+i) for i in t)
primes = set(primerange(1, n*(n+1)//2+1))
if n == 0 or sum(range(1, n+1)) in primes: return int(n == 0)
return c(tuple(range(1, n+1)), 0)
print([a(n) for n in range(18)]) # Michael S. Branicky, May 02 2026
CROSSREFS
KEYWORD
nonn
AUTHOR
Seiichi Manyama, Aug 25 2017
EXTENSIONS
a(0), a(12)-a(23) from Alois P. Heinz, Aug 25 2017
STATUS
approved
