Clear["Global`*"];(*Clear all variables*)
prs=Table;(*产生前125个素数*)
fun:=Module[{n=n0,m=m0,pr,npr,out},
pr=prs[];(*前n个素数*)
npr=Floor@Log+1;(*<=m的素数次幂+1*)
out=Apply(*乘法得到小于m的pn光滑数的个数*)
]
fun=9702对于2 3 5来说,小于2^32的个数是9702
我觉得用二分法,应该可以很快找到第x个这个数的大小 mathematica 发表于 2013-10-23 18:12
(*计算小于等于m的Pn的光滑数的个数的子函数*)
Clear["Global`*"];(*Clear all variables*)
prs=Table;(* ...
可以利用筛法加加减减,然后较快地确定个数,但是个数多了也算得比较慢
RE: 如果我想再加一个bag怎么办?
chyanog 发表于 2013-10-23 17:48当list很大的时候,AppendTo会越来越慢,不如用Internal`Bag{5.515315, 1434246505}{0.905052, 143424650 ...
我想再加一个bag,用来装第1个bag中相邻2项互质的对,写成 bag1=Bag[]行么? liangbch 发表于 2013-10-23 17:10
这个题目的另一个说法是“求5-smooth数",百度知道(34#)给出的代码简单而有效,但有其局限性。用此代码求更 ...
(*计算小于等于m的Pn的光滑数的个数的子函数*)
Clear["Global`*"];(*Clear all variables*)
count=0; minnum=0; maxnum=2^64;
Do[num=
(Prime@1)^n1
*(Prime@2)^n2
*(Prime@3)^n3
*(Prime@4)^n4
;If
,{n1,minnum,Log}
,{n2,minnum,Log}
,{n3,minnum,Log}
,{n4,minnum,Log}
];count
前四个素数构成的光滑数,个数是85349
理论上可以把所有的都计算出来 前31个素数构成的光滑数,计算代码如下:
(*计算小于等于m的Pn的光滑数的个数的子函数*)
Clear["Global`*"];(*Clear all variables*)
count=0; minnum=0; maxnum=2^64;
Do[num=
(Prime@1)^n1
*(Prime@2)^n2
*(Prime@3)^n3
*(Prime@4)^n4
*(Prime@5)^n5
*(Prime@6)^n6
*(Prime@7)^n7
*(Prime@8)^n8
*(Prime@9)^n9
*(Prime@10)^n10
*(Prime@11)^n11
*(Prime@12)^n12
*(Prime@13)^n13
*(Prime@14)^n14
*(Prime@15)^n15
*(Prime@16)^n16
*(Prime@17)^n17
*(Prime@18)^n18
*(Prime@19)^n19
*(Prime@20)^n20
*(Prime@21)^n21
*(Prime@22)^n22
*(Prime@23)^n23
*(Prime@24)^n24
*(Prime@25)^n25
*(Prime@26)^n26
*(Prime@27)^n27
*(Prime@28)^n28
*(Prime@29)^n29
*(Prime@30)^n30
*(Prime@31)^n31
;If
,{n1,minnum,Log}
,{n2,minnum,Log}
,{n3,minnum,Log}
,{n4,minnum,Log}
,{n5,minnum,Log}
,{n6,minnum,Log}
,{n7,minnum,Log}
,{n8,minnum,Log}
,{n9,minnum,Log}
,{n10,minnum,Log}
,{n11,minnum,Log}
,{n12,minnum,Log}
,{n13,minnum,Log}
,{n14,minnum,Log}
,{n15,minnum,Log}
,{n16,minnum,Log}
,{n17,minnum,Log}
,{n18,minnum,Log}
,{n19,minnum,Log}
,{n20,minnum,Log}
,{n21,minnum,Log}
,{n22,minnum,Log}
,{n23,minnum,Log}
,{n24,minnum,Log}
,{n25,minnum,Log}
,{n26,minnum,Log}
,{n27,minnum,Log}
,{n28,minnum,Log}
,{n29,minnum,Log}
,{n30,minnum,Log}
,{n31,minnum,Log}
];count
(*计算小于等于m的Pn的光滑数的个数的子函数*)
Clear["Global`*"];(*Clear all variables*)
count=0; minnum=0; maxnum=2^64;
Do[num=
(Prime@1)^n1
*(Prime@2)^n2
*(Prime@3)^n3
*(Prime@4)^n4
*(Prime@5)^n5
;If
,{n1,minnum,Log}
,{n2,minnum,Log}
,{n3,minnum,Log}
,{n4,minnum,Log}
,{n5,minnum,Log}
];count
前五个素数,代码效率稍微高些
378555 前六个素数1381207
(*计算小于等于m的Pn的光滑数的个数的子函数*)
Clear["Global`*"];(*Clear all variables*)
count=0; minnum=0; maxnum=2^64;
Do[num=
(Prime@1)^n1
*(Prime@2)^n2
*(Prime@3)^n3
*(Prime@4)^n4
*(Prime@5)^n5
*(Prime@6)^n6
;If
,{n1,minnum,Log}
,{n2,minnum,Log}
,{n3,minnum,Log}
,{n4,minnum,Log}
,{n5,minnum,Log}
,{n6,minnum,Log}
];count
hujunhua 发表于 2013-10-24 10:41
我想再加一个bag,用来装第1个bag中相邻2项互质的对,写成 bag1=Bag[]行么?
可以的 (*我猜测的通项公式*)
(*前n个素数,小于等于m的光滑数的个数*)
Clear["Global`*"];(*Clear all variables*)
fun:=Module[{n=n0,m=m0,pn,pn2,pn3,out},
pn=Table;(*前n个素数表*)
pn2=Apply;(*前n个素数的乘积*)
pn3=Apply];(*前n个素数的对数的乘积*)
out=Ceiling[(Log])^n/(n!*pn3)]
]
maxnum=2^64;
fun(*结果精确命中*)
fun(*结果精确命中*)
fun
估计m越大,结果越精确!