除数除数


17

n(k1,k2,...,km)ki2这样和 这里手段是一个多,说: “一个整除b”。如果所有条目必须至少为。对于k1k2...km=n

k1|k2 , k2|k3 ,  , km1|km.
a|bban>1ki2n=1 我们没有这样的因素,因此我们得到一个空的元组。

如果您想知道这是从哪里来的:这种分解在数论中被称为不变因子分解,它被用于有限生成的Abelian组分类中。

挑战

鉴于n输出所有这样的元组ķ1个ķ2ķ对于给定的ñ正好一次,在任何命令你等。允许使用标准输出格式。

例子

  1: () (empty tuple)
  2: (2)
  3: (3)
  4: (2,2), (4)
  5: (5)
  6: (6)
  7: (7)
  8: (2,2,2), (2,4), (8)
  9: (3,3), (9)
 10: (10)
 11: (11)
 12: (2,6), (12)
108: (2,54), (3,3,12), (3,6,6), (3,36), (6,18), (108)

相关:http : //oeis.org/A000688列出n的所有乘法分区


我们可以按相反的顺序输出每个元组吗?(例如12,3,3
Arnauld

1
@Arnauld是的,我认为只要按升序或降序排序就可以了!
瑕疵的

我们可以将输入限制为大于等于2的整数吗?如果不是这样,会使现有的答案无效吗?
尼克·肯尼迪

1
不,规范清楚地表明,可以给任何正整数作为输入,其中包括。如果现在更改它,那么实际上遵守规范的每个人都必须更改答案。ñ=1个
瑕疵的

Answers:



3

05AB1E,13个字节

Òœ€.œP€`êʒüÖP

在线尝试!

Ò                      # prime factorization of the input
 œ€.œ                  # all partitions
     P                 # product of each sublist
      €`               # flatten
        ê              # sorted uniquified
         ʒ             # filter by:
          üÖ           #  pairwise divisible-by (yields list of 0s or 1s)
            P          #  product (will be 1 iff the list is all 1s)

Òœ€.œP用来获取子列表的好方法。我确实很难找到更短的东西。.如果只有类似的内建函数,Åœ但要求乘积而不是求和。;)
Kevin Cruijssen

n = 1失败(请参阅问题评论)
Nick Kennedy


2

JavaScript(V8) 73  70字节

ķķ-1个ķ1个

f=(n,d=2,a=[])=>n>1?d>n||f(n,d+1,a,d%a[0]||f(n/d,d,[d,...a])):print(a)

在线尝试!

已评论

f = (             // f is a recursive function taking:
  n,              //   n   = input
  d = 2,          //   d   = current divisor
  a = []          //   a[] = list of divisors
) =>              //
  n > 1 ?         // if n is greater than 1:
    d > n ||      //   unless d is greater than n,
    f(            //   do a recursive call with:
      n,          //     -> n unchanged
      d + 1,      //     -> d + 1
      a,          //     -> a[] unchanged
      d % a[0] || //     unless the previous divisor does not divide the current one,
      f(          //     do another recursive call with:
        n / d,    //       -> n / d
        d,        //       -> d unchanged
        [d, ...a] //       -> d preprended to a[]
      )           //     end of inner recursive call
    )             //   end of outer recursive call
  :               // else:
    print(a)      //   this is a valid list of divisors: print it

1

05AB1E17 15 14 字节

ѦIиæʒPQ}êʒüÖP

对于较大的测试用例,非常慢。

-1个字节感谢@Grimy

在线尝试。

说明:

Ñ               # Get all divisors of the (implicit) input-integer
 ¦              # Remove the first value (the 1)
  Iи            # Repeat this list (flattened) the input amount of times
                #  i.e. with input 4 we now have [2,4,2,4,2,4,2,4]
    æ           # Take the powerset of this list
     ʒ  }       # Filter it by:
      PQ        #  Where the product is equal to the (implicit) input
         ê      # Then sort and uniquify the filtered lists
          ʒ     # And filter it further by:
           ü    #  Loop over each overlapping pair of values
            Ö   #   And check if the first value is divisible by the second value
             P  #  Check if this is truthy for all pairs

                # (after which the result is output implicitly)

@肮脏的谢谢。并呼吁除数。仍然很慢ñ=8,但所有位都有帮助,如果不花费任何额外的字节来提高性能,那么为什么不使用它呢。:)
Kevin Cruijssen

1
13和更快。感觉还可以更短一些。
Grimmy19年

1

JavaScript,115字节

f=(n,a=[],i=1)=>{for(;i++<n;)n%i||(a=a.concat(f(n/i).filter(e=>!(e[0]%i)).map(e=>[i].concat(e))));return n>1?a:[a]}

稍后我会写一个解释



0

Japt,22 字节

â Åï c à f@¥XשXäv eÃâ

尝试一下

â Åï c à f@¥XשXäv eÃâ     :Implicit input of integer U
â                          :Divisors
  Å                        :Slice off the first element, removing the 1
   ï                       :Cartesian product
     c                     :Flatten
       à                   :Combinations
         f                 :Filter by
          @                :Passing each sub-array X through the following function
           ¥               :  Test U for equality with
            X×             :  X reduced by multiplication
              ©            :  Logical AND with
               Xä          :  Consecutive pairs of X
                 v         :  Reduced by divisibility
                   e       :  All truthy?
                    Ã      :End filter
                     â     :Deduplicate
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.