可构造的n边形


10

构造的n-gon是具有n个边的常规多边形,您仅可以使用罗盘和未标记的标尺来构造。

如高斯所说,唯一可构造n角的n是任意数量的不同费马素数和2的幂的乘积(即n = 2^k * p1 * p2 * ...k是一个整数,并且每一个都p具有不同的费马素数)。

费马素数是可以用正整数表示的F(n)= 2 ^(2 ^ n)+1的素数。唯一已知的费马素数是0、1、2、3和4。

挑战

给定一个整数n>2,说出n-gon是否可构造。

规格

您的程序或函数应采用一个整数或代表该整数的字符串(以一进制,二进制,十进制或任何其他基数表示),并返回或打印真实或虚假值。

这是代码高尔夫球,因此最短的答案为准,因此存在标准漏洞

相关OEIS

例子

3 -> True
9 -> False
17 -> True
1024 -> True
65537 -> True
67109888 -> True
67109889 -> False

Answers:


8

果冻7 5 字节

感谢Sp3000节省2个字节。

ÆṪBSỊ

使用以下分类:

这些也是phi(n)是2的幂的数字。

其中phiEuler的totient函数

ÆṪ        # Compute φ(n).
  B       # Convert to binary.
   S      # Sum bits.
    Ị     # Check whether it's less than or equal to 1. This can only be the
          # case if the binary representation was of the form [1 0 0 ... 0], i.e. 
          e# a power of 2.

在线尝试!

或者(贷记给xnor):

ÆṪ’BP
ÆṪ        # Compute φ(n).
  ’       # Decrement.
   B      # Convert to binary.
    P     # Product. This is 1 iff all bits in the binary representation are
          # 1, which means that φ(n) is a power of 2.

我的Mathematica答案的直接端口长两个字节:

ÆṪ        # Compute φ(n).
  µ       # Start a new monadic chain, to apply to φ(n).
   ÆṪ     # Compute φ(φ(n)).
      H   # Compute φ(n)/2.
     =    # Check for equality.

我不知道Jelly,但您也许可以通过分解并检查最大值是否为2来检查2的幂?您还可以检查其和它的前任对象的按位与是否为
0。– xnor

@xnor嗯,好主意,但是我的尝试是一样的。如果有一种方法可以检查列表的长度是否少于1个字节(少于3个字节),则长度会更短(通过使用仅提供指数列表的分解函数)。我找不到解决办法。
Martin Ender

我看到有E来检查列表中的所有元素是否相等。如果将数字加倍,分解并检查所有系数是否相等怎么办?
xnor

@xnor这也是一个好主意。:)这很可能是随后6个字节,但SP3000指出,有B这让我在5测试
马丁安德

很好。递减,然后二进制,然后乘积的机会更短吗?
xnor

3

Mathematica,24个字节

e=EulerPhi
e@e@#==e@#/2&

使用OEIS中的以下分类:

可计算为数字,以使上位折纸等于上位折纸。

整数的总和 是以下互为素数的正整数的数量。cototient是不是的正整数的数量,即。如果该totient等于cototient,则表示的totient 。φ(x)xxxx-φ(x)φ(x) == x/2

更直接的分类

这些也是phi(n)是2的幂的数字。

最终要长一个字节:

IntegerQ@Log2@EulerPhi@#&

什么是东东和东东?以及东方之语和东方之语的比率?
clismique

@ Qwerp-Derp的totient n是以下n与它们互质的整数n,而cototient是以下与整数互斥的整数n。我将在链接中进行编辑。
Martin Ender'9

Mathematica的内置功能永远不会停止让我惊讶
Sefa 16'9

@ Qwerp-Derp关于第二个问题,这仅意味着您要计算的totient的(共)totient n
Martin Ender

3

视网膜,51 50字节

0+$

+`^(.*)(?=(.{16}|.{8}|....|..?)$)0*\1$
$1
^1$

输入为二进制。前两行除以二的幂,后两行除以所有已知的费马素数(如果实际上是费马素数的乘积)。编辑:感谢@Martin Ender♦,保存了1个字节。


二进制输入很好,还有关于费马素数的假设
Sefa 16'9

2

JavaScript(ES7),61个字节

n=>[...Array(5)].map((_,i)=>n%(i=2**2**i+1)?0:n/=i)&&!(n&n-1)

1

其实是6个位元组

此答案基于Martin Ender的Jelly答案中的xnor算法。欢迎打高尔夫球。在线尝试!

▒D├♂≈π

怎么运行的

         Implicit input n.
▒        totient(n)
 D       Decrement.
  ├      Convert to binary (as string).
   ♂≈    Convert each char into an int.
     π   Take the product of those binary digits.
         If the result is 1,
           then bin(totient(n) - 1) is a string of 1s, and totient(n) is power of two.

0

批次,97个字节

@set/pn=
@for /l %%a in (4,-1,0)do @set/a"p=1<<(1<<%%a),n/=p*!(n%%-~p)+1"
@cmd/cset/a"!(n-1&n)"

输入为标准输入,以十进制表示。这实际上比迭代计算2的幂的幂短1个字节。我使用@xnor的2校验幂保存了1个字节。

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.