Eisenstein整数是形式的复数。
a+bω
其中a,b是整数,并且
ω = e^(2πi/3)
Eisenstein整数在复平面上形成三角形格:

如果一个Eisenstein整数z=a+bω不能写成两个非单位(而不是1,-1,ω,-ω,ω^2或-ω^2)的乘积,那么它就是素数。
输入:一个自然数n。
输出:a+bω形式的Eisenstein素数,其中a,b是小于或等于n的自然数(包括零)。
0→%0
%1→%0
2个→5
3→9
4→13
5→20
这是code-golf,所以最少的字节数获胜
发布于 2016-06-13 13:51:29
Rð_²+×µ€µ³RḊm3,µÆP×1¦3FS和我朱莉娅的回答大致一样。
Initial argument: n
R Compute [1, 2, …, n]
ð_²+× (λ, ρ) —→ (λ − ρ)² + λρ (which is λ² − λρ + ρ²)
µ€ Zip with itself. Call this Q.
µ Refocus argument: Q
³ The initial argument n
RḊm3 Compute candidate green line primes: [2, 5, 8, …, n]
, Call this P. Make pair with argument.
µ Refocus argument: [P, Q]
ÆP Check primality
×1¦3 Multiply the first element by 3
FS Sum everything
(The result is 3·countprimes(P) + countprimes(Q))发布于 2016-06-13 16:17:13
qi,:)_2m*{_:*\:-_*+}%\1>3%3*+:mp1b在线演示
https://codegolf.stackexchange.com/questions/82762
复制相似问题