cp's OEIS Frontend

This is a front-end for the Online Encyclopedia of Integer Sequences, made by Christian Perfect. The idea is to provide OEIS entries in non-ancient HTML, and then to think about how they're presented visually. The source code is on GitHub.

A069870 Smallest prime that can be formed using a partition of n, or 0 if no such prime exists.

This page as a plain text file.
%I A069870 #27 Feb 21 2024 16:51:39
%S A069870 0,2,3,13,5,0,7,17,0,19,11,0,13,59,0,79,17,0,19,137,0,139,23,0,223,
%T A069870 179,0,127,29,0,31,131,0,277,233,0,37,137,0,139,41,0,43,359,0,379,47,
%U A069870 0,409,149,0,151,53,0,487,353,0,157,59,0,61,359,0,163,263,0,67,167,0,367,71,0
%N A069870 Smallest prime that can be formed using a partition of n, or 0 if no such prime exists.
%H A069870 Chai Wah Wu, <a href="/A069870/b069870.txt">Table of n, a(n) for n = 1..10000</a>
%e A069870 a(4) = 13 as the partitions of 4 are (4), (3, 1), ( 2, 2), (2, 1, 1) (1, 1, 1, 1). The primes that can be formed are 13, 31, 211 and 13 is the smallest prime using a partition.
%t A069870 f[n_] := If[ PrimeQ@n, n, If[n > 5 && Mod[n, 3] == 0, 0, Block[{len = PartitionsP[n], p = IntegerPartitions[n], t = {}}, Do[ AppendTo[t, Select[FromDigits /@ Join @@@ IntegerDigits /@ Permutations@p[[i]], PrimeQ@# &]], {i, len}]; t = Union@Flatten@t; If[Length@t > 0, Min@t, 0]] ]]; Array[f, 72] (* _Robert G. Wilson v_, updated by _Jean-François Alcover_, Jan 29 2014 *)
%o A069870 (Python)
%o A069870 from collections import Counter
%o A069870 from sympy.utilities.iterables import partitions, multiset_permutations
%o A069870 from sympy import isprime
%o A069870 def A069870(n):
%o A069870     d = 10**n
%o A069870     smin, m = n+1, d
%o A069870     if n==3 or n%3:
%o A069870         for s in range(1,n+1):
%o A069870             if s>smin:
%o A069870                 break
%o A069870             m = min((k for k in (int(''.join(str(d) for d in a)) for p in partitions(n,m=s) for a in multiset_permutations(Counter(p).elements())) if isprime(k)),default=d)
%o A069870             if m<d:
%o A069870                 smin=s
%o A069870     if m == d:
%o A069870         return 0
%o A069870     else:
%o A069870         return m # _Chai Wah Wu_, Feb 21 2024
%Y A069870 Cf. A069869.
%K A069870 nonn,base
%O A069870 1,2
%A A069870 _Amarnath Murthy_, Apr 21 2002
%E A069870 Edited by _David Wasserman_, May 01 2003
%E A069870 Corrected by _T. D. Noe_, Nov 15 2006