# 第n个具有n个不同素数的数

10

st0le 2011年

1

2

## Python，144个字符

``````R=range
P=[x for x in R(2,99)if all(x%i for i in R(2,x))]
for a in R(input()):
x=n=0
while n<=a:n+=sum(x%p==0for p in P)==a+1;x+=1
print x-1
``````

x = 8大约需要2分钟才能完成。

2

Java，一行170个字符

``````int a(int n) {
int a = 2, t = a, m = 1, i = 1;
Set s = new HashSet();
while (i++ > 0) {
if (t % i == 0) {
t /= i;
if (t == 1) {
if (s.size() == n) {
if (n == m) {
break;
}
m++;
}
t = ++a;
s.clear();
}
i = 1;
}
}
return a;
}
``````

``````int[] f(int n) {
int[] f = new int[n];
for (int i = 0; i < n; i++) {
f[i] = a(i+1);
}
return f;
}
``````

@格雷戈里看更新

@用户，因为我自己对您的评论有误解，请澄清您的请求

2

### Java（未发布）

``````public class M {

public static void main(String[] a) {
final int N = 100000000;
int[] p = new int[N];
for(int f = 2; f * f < N; f++) {
if(p[f] == 0)
for(int k = f; k < N; k += f)
p[k]++;
}
for(int i = 1; i <= 8; i++) {
int c = 0, j;
for(j = 1; j < N && c < i; j++)
if(p[j] == i)
c++;
if(c == i)
System.out.println(i + " = " + --j);
}
}
}
``````

1

## JavaScript，149个字符

``````function(n){function f(x){for(r=[],o=x,z=2;z<=o;x%z?++z:(x/=z,r.indexOf(z)+1?0:r.push(z)));return r}for(c=0,i=1;c<n;)f(++i).length==n?c++:0;return i}
``````

n> = 6时无响应，所以我还没有测试需要多长时间（我的浏览器每10秒钟弹出一个挂起的脚本通知，所以我无法准确计时，并且我不想完全挂起。选中“不再显示此内容” ...）

``````function(n){function F(){function f(x){for(r=[],o=x,z=2;z<=o;x%z?++z:(x/=z,r.indexOf(z)+1?0:r.push(z)));return r}for(c=0,i=1;c<n;)F(++i).length==n?c++:0;return i}for(a=[];n>0;n--)a.push(f());return a}
``````

0

# J，32个字节

``````({"0 1~i.@#)(]/.~#@~.@q:)
``````

By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.