%I#9 2023年8月5日12:01:28
%S 2,7,22,11,34,17,52,26,13,40,20,10,5,16,8,4,2,7,22,11,34,17,52,26,13,
%电话40,20,10,5,16,8,4,2,7,22,11,34,17,52,26,13,40,20,10,5,16,8,42,7,22,
%U 11,34,17,52,26,13,40,20,10,5,16,8,4,2,7,22,11,34,17,52,26,13,40,20,10,5,16,8
%N a(0)=2;如果a(n-1)是素数,则a(n)=a(n-1)*3+1;如果a(n-1)/(最小素数因子)是复合的,则a。
%C a(n)在16次迭代后重复自身。峰值为a(6)=52。
%这个函数在性质上与Collatz的3x+1问题类似,只是它处理的是素性而不是奇偶性。
%H维基百科,<a href=“http://en.wikipedia.org/en/wiki/Divisor“>除数</a>
%H维基百科,<a href=“http://en.wikipedia.org/en/wiki/Prime_number“>素数</a>
%e a(0)=2
%e a(1)=2*3+1=7,因为a(0)是素数。
%e a(2)=7*3+1=22,因为a(1)是素数。
%e a(3)=22/2=11,因为a(2)的最小素因子是2。
%t嵌套列表[If[PrimeQ[#],3#+1,#/FactorInteger[#][[1,1]]&,2,80](*或*)PadRight[{},80,{2,7,22,11,34,17,52,26,13,40,20,10,5,16,8,4}](*_哈维·戴尔,2023年8月5日*)
%o(Python)
%o导入数学
%o来自sympy import isprime
%o a=[2]
%o而不是a[:-1]中的[-1]:
%o如果是素数(a[-1]):
%o a.追加(a[-1]*3+1)
%o其他:
%o对于范围(2,int(math.sqrt(a[-1]))+1)中的div:
%o如果不是[-1]%div:
%o a.append(a[-1]//目录)
%o中断
%o打印(a)
%Y参考A000040,A175867。
%K容易,不是
%0、1
%A _格兰特·加西亚,2010年10月2日
|