这个网站是通过捐款来支持的。OEIS基金会.

M. F. Hasler/A0399

从奥伊斯维基
跳转到:导航搜索

A0399=素数,使得每一个不同的数字排列是复合的(包括排列与前导零点):

2, 3, 5,7, 11, 19,23, 29, 41,43, 47, 53,59, 61, 67,83, 89, 151,211, 223, 227,229, 233, 257,263, 269, 353,383, 409, 431,433, 443, 449,487, 499, 523,487, 499, 523,γ,γ,γ,γ,γ

这个序列的代码:(添加到OEIS.Org/A0399《01》第2018卷

A039986_row(n)={ /* compute terms of length n */
 if(n>1 /* criteria for the last digit apply only for length > 1 */
 , local(D=eval(Vec("0245681379")) /* all possible digits, with possible ending digits coming last: equivalent to vecsort([0..9],(a,b)->isprime(10+a)-isprime(10+b)) */
   , u=vectorv(n, i, 10^(n-i)) /* powers of 10: dot product d.u is slightly faster & shorter than fromdigits(d) */
   , nextperm()= /* change the "global" variable p to the "next" permutation of [1..n] */
       for(i=2, n, /* i = the position of the index we will decrease. (123)……213,132……(*=)(t=p[i] - 1)其次,/*我们能减少这个索引而不得到0吗?否则转到下一个位置*/*(set)(set(p[i++n.]),t)这个左边的索引可用吗?*[t]=d[p[i] ] /*这会改变数字吗?*(或),T—γ(下)(2)/*…否则尝试下一个更小;如果我们运行到0 */i,转到下一个位置;i i n/*最右边的位置?*/
         || bittest(650, d[t]) /* then digit must be among 1379 */
         || return /* else (a digit other than 1379 reached the right) we're done: all subsequent perms will be composite */;
         /* now all criteria are satisfied if we replace p[i] with the smaller t & reorder the other indices to the left of p[i] */
         p=concat([setminus(Set(p[1..i]), [t]) /* reorder the indices (other than t) to the left */
                  , t, p[i+1..n]]); /* then append t (= new p[i]), and the other indices to the right (unchanged) */
         return(1)
       ) /* end for(i); also the end of nextperm(): returns 0 if all permutations are done */
   , L=List() /*list of results*/, f /* "found" */, p /* the permutation */, d /* the chosen digits in increasing order */
   ) /* end of "local" variables and procedures; now follows the main loop */;
   forvec( i=vector(n, j, [7^(j==n), 10]) /* selection of the digits: indices 1..9 correspond to digits '0','2',...,'7','9' ; only increasing vectors i are generaTED和最后一个第n个索引必须是>7,即,数字1,3,7或9 */*,VECUM(D=VECUBED(D,I)/*列表对应于索引列表I */*)%%的下一个/ *和的数字必须不可被3*/ /;f=0 / *没有发现到目前为止* /;p=[1…n] /*初始排列=ID*/;直到(!)NEXPURME()/*在完成循环体之后,转到下一个相关排列;如果所有都完成,则结束。*(/ p)/*(VP(D,P)/*以排列顺序P**/*U/*转换为数字*//**素数?*/ 
       && (f && next(2) /* if we had already found another prime: no good; goto next selection of digits */
           || f=p /*else set "found" equal to the current permutation */)
     ) /* end of until() */ ; 
     f /*if we have found exactly one prime */ && d[f[1]] /* first digit nonzero */ 
     && listput(L, vecextract(d, f)*u) /* add the corresponding number to the list */
   , 1 /* only consider increasing indices */
   ); 
   Set(L) /* return the solutions in increasing order */
 , /* else (n=1): return the 1-digit primes (2,3,5,7) */
   primes(4) /* equivalent to [2,3,5,7] but OEIS inserts a space after each "," so the explicit list takes more space */
 )/*end if n>1*/
} \\ Returns all terms with n digits. - M. F. Hasler,JUL 01 2018