n番目のアーロン数を見つける


14

バックグラウンド

ルース=アーロン・ペアは、連続的な正の整数のペアであるnn+1、各整数の素因数の合計は(計数素因数を繰り返す)等しくなるようにします。たとえば、(714,715)は、、およびであるため714=2*3*7*17、ルースとアーロンのペアです。ルースとアーロンのペアの名前は、1935年5月25日から1974年4月8日までハンクアーロンがホームランを打ったまでの世界記録としてのベーブルースのキャリアホームラン合計を参照して、カールポメランスによって選ばれました。このNumberphileビデオで、これらの数字の魅力的な歴史について詳しく知ることができます。715=5*11*132+3+7+17=5+11+13=29714715

ゴール

正の整数を指定しnnthアーロン数を出力する完全なプログラムまたは関数を記述します。ここで、nth数はnthルース-アーロンペアの大きい整数に定義されます。したがってn番目アロンの数でa(n)+1あり、a(n)あるnOEISシーケンスにおける番目用語A039752は

テストケース

最初のいくつかのアーロン数は

6,9,16,78,126,715,949,1331,1521,1863,2492,3249,4186,4192,5406,5561,5960,6868,8281,8464,10648,12352,14588,16933,17081,18491,20451,24896,26643,26650,28449,28810,33020,37829,37882,41262,42625,43216

ルール


確かに、「多重度を数える」とは、20-> 2、2、5ではなく、2、5を意味しますか?
ハイパーニュートリノ

@Okx Iは、私はちょうど私が彼のYouTubeのプロフィールをリフレッシュしたときに、彼は(ない私)正確に1以上の加入者だったことに気づいた
氏Xcoder

@HyperNeutrinoはい。より明確にするために編集します。
-ngenisis

0〜1のインデックス作成を選択できますか?
ミスターXcoder

3
私も、今日のNumberphileのビデオを見ました
-shooqie

回答:


7

05AB1E11 10 9バイト

Emignaのおかげで
-1バイトAdnanのおかげで-1バイト

µN>Ð<‚ÒOË

説明:

µ            While the counter variable (which starts at 0) is not equal to the input:
 N>          Store the current iteration index + 1, and then create an array with
   Ð<‚       [current iteration index + 1, current iteration index]
      ÒO     Get the sum of the prime factors of each element
        Ë    If all elements in the array are equal,
             implicitly increment the counter variable

1インデックス付き。

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


1
可能な場合は説明してください:)
Xcoder氏

@ Mr.Xcoderが追加されました。
Okx

10バイト:µN>Ð<‚ÒO˽
Emigna

@Emignaああ、いいね。
Okx

2
@Adhnan本当に?それはクレイジーな言語機能です。
Okx

5

11 9バイト

@Leoによる巧妙なゴルフのおかげで-2バイト

€∫Ẋ¤=oΣpN

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

説明

  Ẋ     N   -- map function over all consecutive pairs ... of natural numbers           [(1,2),(2,3),(3,4),(4,5)...]
   ¤=       --   are the results of the following function equal for both in the pair?
     oΣp    --     sum of prime factors                                                   [0,0,0,0,1,0,0,1,0,0,0,0,0,0,1,0,0,0,0,0]
 ∫          -- cumulative sum                                                           [0,0,0,0,0,1,1,1,2,2,2,2,2,2,2,3,3,3,3,3]                
€           -- the index of the first value equal to the input

1
素晴らしい仕事、私はほぼ同じアイデアを投稿しようとしていた:)
レオ

2
レオ

1
@Leo Ooh、€∫本当に素晴らしいトリックです!そして、怠zyな言語でのみ動作するもの。;)
ズガルブ

@レオ非常に賢い。
H.PWiz

3

Pyth23 20バイト

これは1インデックスです。

WhQ=-QqsPZsPhZ=+Z1;Z

テストスイートまたはオンラインでお試しください!


説明

WhQ = -QqsPZsPhZ = + Z1; Z-完全なプログラム。標準入力から入力を取得します。

WhQ-Qはまだ0より大きい
       sPZ-Zの素因数の合計
          sPhZ-Z + 1の素因数の合計。
      q-上記が等しい場合:
   = -Q-等しい場合はQを1減らし、等しくない場合は0減らします。
              = + Z1; -反復ごとにZを増分します。
                   Z-出力Z 

3

ゼリー、12 バイト

;‘ÆfS€Eµ⁸#Ṫ‘

負でない数を取り、返す単項リンク

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

どうやって?

;‘ÆfS€Eµ⁸#Ṫ‘ - Link: number, n
         #   - n-find (counting up, say with i, from implicit 1)
        ⁸    - ...number of matches to find: chain's left argument, n
       µ     - ...action: the monadic chain with argument i:
 ‘           -   increment = i+1
;            -   concatenate = [i,i+1]
  Æf         -   prime factors (with duplicates, vectorises)
    S€       -   sum €ach
      E      -   all (two of them) equal?
          Ṫ  - tail, the last matching (hence nth) i
           ‘ - increment (need to return i+1)

でバイトを保存します;’ÆfS€E_Ịµ#
エリックアウトゴルファー

まだ尾が必要です。
ジョナサンアラン

1
そして、それだけでテストのために得られるものです1
エリックアウトゴルファー

3

PHP、93 92 91 + 1バイト

while(2+$argn-=$a==$b)for($b=$a,$a=!$x=$n+=$k=1;$k++<$x;)for(;$x%$k<1;$x/=$k)$a+=$k;echo$n;

でパイプとして実行する-nR、オンラインで試してください

-2バイトの3インデックス付き(引数の最初のアーロン数3):削除2+

壊す

while(2+$argn       # loop until argument reaches -2 (0 and 1 are false positives)
    -=$a==$b)           # 0. if factors sum equals previous, decrement argument
    for($b=$a,          # 1. remember factors sum
        $a=!            # 3. reset factors sum $a
        $x=$n+=         # 2. pre-increment $n and copy to $x
        $k=1;$k++<$x;)  # 4. loop $k from 2 to $x
        for(;$x%$k<1;       # while $k divides $x
            $x/=$k)             # 2. and divide $x by $k
            $a+=$k;             # 1. add $k to factors sum
echo$n;             # print Aaron number $n

3

MATL、17バイト

`@:"@Yfs]vd~sG<}@

1ベース。非常に遅い。

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

説明

`        % Do...while
  @      %   Push iteration index k, starting at 1
  :      %   Range [1 2 ... k]
  "      %   For each j in [1 2 ... k]
    @    %     Push j
    Yf   %     Row vector of prime factors
    s    %     Sum
  ]      %   End
  v      %   Concatenate whole stack into a column vector
  d      %   Consecutive differences. A zero indicates a Ruth-Aaron pair
  ~s     %   Number of zeros
  G<     %   Is it less than the input? If so: next k. Else: exit loop
}        % Finally (execute right before when the loop is exited)
  @      %   Push current k
         % Implicit end. Implicit display


2

Pyth、12 11バイト

e.fqsPtZsPZ

1からインデックスを作成すると、バイトが削除され、PythがJellyよりも先になります


説明

e.fqsPtZsPZ-完全なプログラム。標準入力から入力を取得します。

ef-最初の$ input番号のリストの最後の要素
   q-等しい 
    ss-の合計
     PtZ PZ-$ number-1および$ numberの素因数


1

ゼリー、17バイト

ÆfS=’ÆfS$$µ³‘¤#ṖṪ

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

説明

ÆfS=’ÆfS$$µ³‘¤#ṖṪ  Main link, argument is z
              #    Find the first       elements that satisfy condition y: <y><z>#
           ³‘¤                    z + 1
          µ        Monadic link, where the condition is:
  S                The sum of
Æf                            the array of primes that multiply to the number
   =               equals
       S           The sum of
     Æf                       the prime factors of
    ’                                              the number before it
        $$         Last two links as a monad, twice
               Ṗ   k -> k[:-1]
                Ṫ  Last element (combined with `pop`, gets the second last element)

1インデックス付き


1
デフォルトのルールで2-indexingが許可されているかどうかわかりません。
氏Xcoder

@ Mr.Xcoder確かに修正されました。
ハイパーニュートリノ



0

パイソン2119の104 102 101バイト

f=lambda n,k=2:n/k and(f(n,k+1),k+f(n/k))[n%k<1]
i=input();g=0
while-~i:i-=f(g)==f(g+1);g+=1
print(g)

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

-17バイト@ovsのおかげで!

-1バイト@notjaganのおかげで

素因数分解アルゴリズムの功績はデニスにあります。1インデックス付き。


注:これは非常に遅く、非効率的です。7を超える入力import syssys.setrecursionlimit(100000)、設定して実行しない限りクラッシュしますが、理論的には機能します。


f素因数の合計を計算する関数を作成して104バイト
ovs

バイトカウントを追跡する(そして編集内容にコメントを付ける)場合は素晴らしいでしょう。
タイタス

(f(n,k+1),k+f(n/k))[n%k<1]別の-2バイト。これによりさらに遅くなります。
ovs

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