分解リーダーの変更の削減


12

tl; dr:縮約素因数分解リーダーが変更される値を出力します。

すべての正の整数には一意の素因数分解があります。縮約素因数分解を、素因数の多重度のリストだけで、素因数のサイズ順に並べてみましょう。例えば、の減少素因数分解が1980ある[2, 2, 1, 1]、なぜなら1980 = 2 * 2 * 3 * 3 * 5 * 11

次に、の整数上で、各素因数分解が発生する頻度を記録しましょう[1, 2, ..., n]。たとえば、[1, 2, ..., 10]では、次の縮約素因数分解が発生します。

[1]: 4 (2, 3, 5, 7)
[2]: 2 (4, 9)
[1, 1]: 2 (6, 10)
[]: 1 (1)
[3]: 1 (8)

n最も頻繁に起こる減らされた素因数分解に至るまでリーダーを呼びます[1, 2, ..., n]。したがって、の簡約素因数分解リーダーはn = 10です[1]n縮小された素因数分解と同じかそれ以下の最大整数のサイズによって関係が壊れ、最大整数が小さいほど良いです。たとえば、最大のn = 60素因数分解[1]を最大[1, 1]17回まで実行します。その範囲の最大整数[1, 1]58であり、最大整数[1]はである59。したがって、でn = 60、簡約素因数分解リーダーは[1, 1]です。

n縮小された素因数分解リーダーがどこで変化するかという値に興味があります。それらは、n還元された素因数分解リーダーがまでの還元された素因数分解リーダーと異なる場所の値ですn-1。エッジケースとして、n = 1リーダーはのために存在しないため、リーダーシップはで変化すると言いn = 0ます。

あなたの課題は出力することです。

目的の出力の初期シーケンスは次のとおりです。

1, 3, 58, 61, 65, 73, 77, 1279789, 1280057, 1280066, 1280073, 1280437, 1280441, 1281155, 1281161, 1281165, 1281179, 1281190, 1281243, 1281247, 1281262, 1281271, 1281313, 1281365

許可される出力スタイルは次のとおりです。

  • 無限の出力。
  • 最初のkリーダーが変更されkます。入力はどこにあります。
  • k第リーダーの変更、k入力されました。

k インデックスは0または1です。

これはコードゴルフです。不明な点がある場合は、コメントでお尋ねください。幸運を!


リーダーは、最大で/ k未満の値で変化しますか?
user202729

@ user202729私はノーと言うつもりです-それは挑戦を少し異なったものにします。
isaacg

正の整数の考え方を定義したので、1または3のいずれかでシーケンスを開始できるようにしたい場合があります(または、「n減らされた素因数分解リーダーが減らされた素因数分解リーダーと異なる最大値n-1")
ジョナサンアラン

@JonathanAllan私は物事を変えていませんが、挑戦の関連部分を明確にしました。
isaacg

回答:


3

、18バイト

m←ġ(←►Lk=mȯmLgpṫ)N

オンラインでお試しください! これにより、無限リストが印刷されます。プログラムは結果が最初の7つの値に切り捨てられます。これは、プログラムが非常に非効率的であり、TIOでその後タイムアウトになるためです。

カッコはいですが、どうやって取り除くかわかりません。

説明

m←ġ(←►Lk=mȯmLgpṫ)N  No input.
                 N  The list of natural numbers [1,2,3,4,..
  ġ(            )   Group into slices according to this function.
                    Each slice corresponds to a run of numbers with equal return values.
    ←►Lk=mȯmLgpṫ    Function: from n, compute the reduced factorization leader in [1..n].
                     As an example, take n = 12.
               ṫ     Reversed range: [12,11,10,9,8,7,6,5,4,3,2,1]
         m           Map over this range:
              p       Prime factorization: [[2,2,3],[11],[2,5],[3,3],[2,2,2],[7],[2,3],[5],[2,2],[3],[2],[]]
             g        Group equal elements: [[[2,2],[3]],[[11]],[[2],[5]],[[3,3]],[[2,2,2]],[[7]],[[2],[3]],[[5]],[[2,2]],[[3]],[[2]],[]]
          ȯmL         Take length of each run: [[2,1],[1],[1,1],[2],[3],[1],[1,1],[1],[2],[1],[1],[]]
       k=            Classify by equality: [[[2,1]],[[1],[1],[1],[1],[1]],[[1,1],[1,1]],[[2],[2]],[[3]],[[]]]
                     The classes are ordered by first occurrence.
     ►L              Take the class of maximal length: [[1],[1],[1],[1],[1]]
                     In case of a tie, ► prefers elements that occur later.
    ←                Take first element, which is the reduced factorization leader: [1]
                    The result of this grouping is [[1,2],[3,4,..,57],[58,59,60],[61,62,63,64],..
m←                  Get the first element of each group: [1,3,58,61,65,73,77,..

なぜ機能し►=ない。maxBy後で要素を好みますか?
H.PWiz

@ H.PWiz問題は、同点の場合、逆の範囲で最初に現れる要素が最大になる要素を優先する必要があることです。可能な限り最新、または同様に、増加する範囲の最後の出現が可能な限り早いがあることです。►=どちらもしません。
ズガルブ

1

JavaScript(ES6)、120バイト

N番目のリーダーの変更を1インデックスで返します。

N=>(F=m=>N?F((F[k=(D=(n,d=2,j)=>d>n?j:n%d?D(n,d+1)+(j?[,j]:[]):D(n/d,d,-~j))(++n)]=-~F[k])>m?F[N-=p!=k,p=k]:m):n)(n=p=0)

デモ

コメント済み

ヘルパー関数D()、逆順でnの縮約素因数分解を返します。

D = (n, d = 2, j) =>             // n = input, d = divisor, j = counter
  d > n ?                        // if d is greater than n:
    j                            //   append j and stop recursion
  :                              // else:
    n % d ?                      //   if d is not a divisor of n:
      D(n, d + 1) + (            //     recursive call with n unchanged and d = d + 1
        j ?                      //     if j is not undefined:
          [,j]                   //       append a comma followed by j
        :                        //     else:
          []                     //       append nothing
      )                          //
    :                            //   else:
      D(n / d, d, -~j)           //     recursive call with n divided by d and j = j + 1

メイン機能:

N =>                             // N = target index in the sequence
  (F = m =>                      // m = # of times the leader has been encountered
    N ?                          // if N is not equal to 0:
      F(                         //   do a recursive call to F():
        (F[k = D(++n)] =         //     increment n; k = reduced prime factorization of n
                         -~F[k]) //     increment F[k] = # of times k has been encountered
        > m ?                    //     if the result is greater than m:
          F[N -= p != k,         //       decrement N if p is not equal to k
                         p = k]  //       update p and set m to F[p]
        :                        //     else:
          m                      //       let m unchanged
      )                          //   end of recursive call
    :                            // else:
      n                          //   stop recursion and return n
  )(n = p = 0)                   // initial call to F() with m = n = p = 0

1

スタックス、24 バイト

Ç▓Δk/‼&²Θºk∙♥╜fv╛Pg8╝j♀§

このプログラムは入力を受け取らず、理論的には無限の出力を生成します。8番目の要素には1年以上かかるため、「理論的に」と言います。

実行してデバッグする

同じプログラムの対応するASCII表現はこれです。

0WYi^{|n0-m|=c:uny=!*{i^Q}Md

スタックの最後のリーダーを保持します。整数表現を反復します。因子表現に明確なモードがあり、最後のモードと異なる場合は、それを出力します。

0                               push zero for a placeholder factorization
 W                              repeat the rest of the program forever
  Y                             store the last factorization in the y register
   i^                           i+1 where i is the iteration index
     {    m                     using this block, map values [1 .. i+1]
      |n0-                          get the prime exponents, and remove zeroes 
           |=                   get all modes
             c:u                copy mode array and test if there's only one
                ny=!            test if mode array is not equal to last leader
                    *           multiply; this is a logical and
                     {   }M     if true, execute this block
                      i^Q       push i+1 and print without popping
                           d    discard the top of stack
                                    if it was a leader change, this pops i+1
                                    otherwise it pops the mode array
                                at this point, the last leader is on top of 
                                the stack

0

Python 2、145バイト

m=i=0;f=[]
while 1:
 i+=1;a=i;d=[0]*-~i;k=2
 while~-a:x=a%k>0;k+=x;a/=x or k;d[k]+=1-x
 k=filter(abs,d);f+=k,;c=f.count
 if c(k)>c(m):print i;m=k

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

非ゴルフ

m=0                    # reduced prime factorizations leader
i=0                    # current number
f=[]                   # list of reduced prime factorizations
while 1:               # Infinite loop:
  i+=1                 #   next number
  a=i                  #   a is used for the prime factorization
  d=[0]*-~i            #   this lists stores the multiplicity
  k=2                  #   current factor
  while~-a:            #   As long as a-1 != 0:
    x=a%k>0            #      x := not (k divides a)
    k+=x               #      If k does not divide a, go to the next factor
    a/=x or k          #      If k does not divide a,
                       #         divide a by 1,
                       #         else divide it by k
    d[k]+=1-x          #      add 1 to the multiplicity of k if k divides a
  k=filter(abs,d)      #   Only keep non-zero multiplicities
                       #     k is now the reduced prime factorization of i
  f+=k,                #   append k to the list of reduced prime factorizations
  c=f.count            #   c(x) := number of occurences of x in f
  if c(k)>c(m):        #   has the current reduced prime factorization
                       #    appeared more often than the leader?
    print i;m=k        #     print the current number, set new leader

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


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