除算除数の除算


17

n(k1,k2,...,km)ki2k1k2...km=n

k1|k2 , k2|k3 ,  , km1|km.
a|bban>1ki2n=1 そのような要因はないため、空のタプルを取得します。

これがどこから来るのか興味がある場合:この分解は、数論で不変因子分解として知られており、有限生成アーベル群の分類に使用されます。

チャレンジ

与えられたの出力の全てなのタプル与えられたためのようなものは何でも順番あなたが、正確に一度だけ。標準の出力形式が許可されています。n(k1,k2,...,km)n

  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はい、昇順または降順で並べ替えられていれば問題ありません。
flawr

入力を2以上の整数に制限できますか?そうでない場合、既存の回答の一部が無効になりますか?
ニックケネディ

1
いいえ、仕様では、を含む任意の正の整数を入力として指定できることが明確に示されています。私が今それを変更した場合、実際に仕様を順守している人は全員、答えを変更しなければなりません。n=1
19:21の

回答:



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で失敗(質問に関するコメントを参照)
ニックケネディ


2

JavaScript(V8) 73  70バイト

タプルを降順ます。(km,km1,...,k1)

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

大きなテストケースでは非常に遅い。

@Grimyのおかげで-1バイト。

オンラインでお試しください。

説明:

Ñ               # 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)

@Grimyありがとう。そして、除数の良い呼び出し。ではまだ非常に遅いですが、すべてのビットが役立ちます。パフォーマンスを向上させるために追加のバイトが必要ない場合は、使用しないでください。:)n=8
ケビンクルーッセン

1
13以上。まだ短くなるように感じます。
Grimmy

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]}

後で説明します


1

Wolfram言語(Mathematica)78 76 72 71 67バイト

If[#>(p=1##2),Join@@If[i∣##,##~#0~i,{}]~Table~{i,2,#/p},{{##2}}]&

オンラインでお試しください!

再帰検索ツリー。


ブルートフォースソリューション、64バイト

Union@Cases[Range@#~Tuples~#,{a__,__}/;1a==#&&a>=2&&1∣a:>{a}]&

些細な修正私のMathematicaソリューションリストのnのすべての乗法のパーティション

これはタプルをチェックする必要があるため、同じロジックを使用してより効率的なバージョンを試してくださいnn


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
弊社のサイトを使用することにより、あなたは弊社のクッキーポリシーおよびプライバシーポリシーを読み、理解したものとみなされます。
Licensed under cc by-sa 3.0 with attribution required.