编写一个以正整数n作为输入的程序或函数,并输出安全素数小于或等于n的所有索菲杰曼素数。素数p是苏菲日耳曼素数,如果2p+1也是素数。素数p是一个安全素数如果p=2q+1,其中q也是素数。输出应该是索菲日耳曼素数的列表,这些素数也是安全素数,仅按升序排列。
[20] => 5, 11
[10000] => 5, 11, 23, 83, 179, 359, 719, 1019, 1439, 2039, 2063, 2459, 2819, 2903, 2963, 3023, 3623, 3779, 3803, 3863, 4919, 5399, 5639, 6899, 6983, 7079, 7643, 7823
[1000] => 5, 11, 23, 83, 179, 359, 719输出素数p,使得\frac{p-1}{2}和2p+1都小于素数,等于输入中给定的特定n。最短字节答案将获胜,如果字节相等,则会出现领带。
发布于 2023-03-09 09:31:51
发布于 2023-03-09 10:17:31
Lʒx>y2÷)pPL # Push a list in the range [1, (implicit) input-integer]
ʒ # Filter it by:
x # Double the current value (without popping)
> # And increase it by 1
y # Push the current value again
2÷ # Integer-divide it by 2
) # Wrap all three values into a list: [n,2n+1,(n-1)/2]
p # Check for each whether it's a prime number
P # Check if all three are truthy
# (after which the filtered list is output implicitly as result)https://codegolf.stackexchange.com/questions/258958
复制相似问题