首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >生成n‘the费米-狄拉克素数

生成n‘the费米-狄拉克素数
EN

Code Golf用户
提问于 2022-10-24 07:23:51
回答 5查看 1.9K关注 0票数 15

费米-狄拉克素数是形式p^{2^k}的素数幂,其中p是素数和k \geq 0,或者换句话说,是整数幂为2的素数。它们被列为整数序列A050376。虽然正规素因式分解一般不包含一组不同的素数(例如24=2 \times 2 \times 2 \times 3),但费米-狄拉克素数分解最多包含每一个费米-狄拉克素数( 24=2 \times 3 \times 4 )。

您的任务是编写一个以整数n作为输入并输出n'th Fermi素数或从标准序列IO规则中选择任何其他选项的程序。

以字节为单位的最短代码获胜,没什么好笑的事

1-索引

代码语言:javascript
运行
复制
1, 2
2, 3
3, 4
4, 5
5, 7
6, 9
7, 11
8, 13
9, 16
10, 17
100, 461
1000, 7649
6605, 65536
10000, 103919
100000, 1296749
1000000, 15476291
EN

回答 5

Code Golf用户

发布于 2022-10-24 09:20:45

布氏对数,11个字节(生成器),16个字节(完整程序)

代码语言:javascript
运行
复制
.ℕ₂ḋ=l~^h2∧

在网上试试!

代码语言:javascript
运行
复制
;I{.ḋ=l~^h2∧}ᶠ⁽b

在网上试试!

生成器是1索引的.整个程序输出第一个n素数幂,0索引。

其实没那么慢。

解释

代码语言:javascript
运行
复制
.ℕ₂                  Output is an integer in [2,+inf)
   ḋ                 Its prime decomposition…
    =                …is a list of equal elements…
     l               …with a length…
      ~^h2∧          …being a power of 2



;I{          }ᶠ⁽      Find the first <Input> results of the following predicate:
   .ḋ                   The prime decomposition of the Output…
     =                  …is a list of equal elements…
      l                 …with a length…
       ~^h2∧            … being a power of 2
                b     Remove the first result (1, whose prime decomposition is the empty list)
票数 6
EN

Code Golf用户

发布于 2022-10-25 01:58:09

Python,60字节

代码语言:javascript
运行
复制
L={n:=1}
while{n}<=L or[print(n),L:=L|{n*l for l in L}]:n+=1

在网上试试!

无限期输出。

复杂性在N中是指数型的,是费米-狄拉克素数。

怎么做?

利用OP:维护到目前为止发现的费米-狄拉克素数集的每个子集的分解性质。这个集合中最小的数是下一个费米-狄拉克素数,不管它是传统的素数还是第二次方的幂。

票数 6
EN

Code Golf用户

发布于 2022-10-24 08:39:20

05AB1E,12 字节数

代码语言:javascript
运行
复制
>Åp¤Ýoδm˜êNè

0-索引。

蛮力法,所以输入越大,速度越慢.

在网上试试验证前10个测试用例 (用I>代替¤以加快速度,尽管n\geq15仍然超时)。

Explanation:

代码语言:javascript
运行
复制
>             # Increase the (implicit) input by 1 (for edge-case n=0)
 Åp           # Pop and push a list of the first input+2 amount of prime numbers
   ¤          # Push its last/largest prime (without popping the list)
    Ý         # Pop and push a list in the range [0,max_prime]
     o        # Get 2 to the power each value in this list
      δ       # Apply double-vectorized on the two lists:
       m      #  Exponentiation
        ˜     # Flatten the list of lists
         ê    # Sorted-uniquify it
          Iè  # Get the input'th value of this list
              # (after which it is output implicitly as result)
票数 5
EN
页面原文内容由Code Golf提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://codegolf.stackexchange.com/questions/253682

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档