ค้นหาหมายเลขแอรอนที่ n


14

พื้นหลัง

Ruth-แอรอนคู่คือคู่ของจำนวนเต็มบวกติดต่อกันnและn+1ดังกล่าวว่าผลรวมของปัจจัยสำคัญ (การนับซ้ำแล้วซ้ำอีกปัจจัยสำคัญ) ของแต่ละจำนวนเต็มมีค่าเท่ากัน ยกตัวอย่างเช่น(714,715)เป็นคู่รู ธ -อาโรนตั้งแต่714=2*3*7*17, และ715=5*11*13 2+3+7+17=5+11+13=29คู่ชื่อรู ธ - อารอนได้รับเลือกจากคาร์ลพอเมอเรนซ์ในการอ้างอิงถึงอาชีพของเบ๊บรู ธรวม714อยู่ในสถิติโลกตั้งแต่วันที่ 25 พฤษภาคม 1935 จนถึง 8 เมษายน 1974 เมื่อแฮงค์แอรอนเข้า715บ้าน คุณสามารถเรียนรู้เพิ่มเติมเกี่ยวกับประวัติความเป็นมาที่น่าสนใจของตัวเลขเหล่านี้ในวิดีโอ Numberphile

เป้าหมาย

เขียนโปรแกรมหรือฟังก์ชั่นที่สมบูรณ์ซึ่งให้เลขจำนวนเต็มบวกnเอาท์พุทnเลขอาโรนที่nหมายเลขนั้นถูกกำหนดให้เป็นจำนวนเต็มที่มากขึ้นของnคู่รู ธ - อารอน ดังนั้นnเลขอาโรนa(n)+1ที่ 1 a(n)คือnเทอมที่ 1 ในลำดับ OEIS A039752 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 ใช่ไหม?
HyperNeutrino

@Okx ฉันเป็นฉันเพิ่งสังเกตเห็นว่าเมื่อฉันรีเฟรชโปรไฟล์ Youtube ของเขาเขามีสมาชิกอีก 1 คน (ไม่ใช่ฉัน)
Mr. Xcoder

@HyperNeutrino ใช่ ฉันจะแก้ไขให้ชัดเจนยิ่งขึ้น
ngenisis

เราสามารถเลือกการจัดทำดัชนีระหว่าง 0 ถึง 1 ได้หรือไม่
Mr. Xcoder

3
ฉันก็ดูวิดีโอ Numberphile ของวันนี้ด้วย
shooqie

คำตอบ:


7

05AB1E , 11 10 9 ไบต์

-1 ไบต์ขอบคุณ Emigna
-1 ไบต์ขอบคุณ Adnan

µ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 Ah คนดี
Okx

2
@Adhnan จริงเหรอ? นั่นเป็นคุณสมบัติภาษาบ้า
Okx

5

Husk , 11 9 ไบต์

-2 ไบต์ต้องขอบคุณสนามกอล์ฟที่ฉลาดโดย @Leo

€∫Ẋ¤=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
เป็นงานที่ดีฉันกำลังจะโพสต์ความคิดเดียวกันอย่างมีนัยสำคัญ :)
Leo


1
@Leo Ooh €∫เป็นเคล็ดลับที่ดีจริงๆ! และอีกอันหนึ่งที่ใช้งานได้ในภาษาขี้เกียจ ;)
Zgarb

@Leo ฉลาดมาก
H.PWiz

3

Pyth , 23 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µ⁸#Ṫ‘

ลิงก์ monadic ที่รับและส่งคืนตัวเลขที่ไม่เป็นลบ

ลองออนไลน์!

อย่างไร?

;‘Æ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_Ịµ#บันทึกไบต์ด้วย
Erik the Outgolfer

ยังคงต้องการหาง
Jonathan Allan

1
1และนั่นคือสิ่งที่คุณได้รับการทดสอบเท่านั้นด้วย
Erik the Outgolfer

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-based ช้ามาก.

ลองออนไลน์!

คำอธิบาย

`        % 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

3

Mathematica, 97 ไบต์

(t=r=1;While[t<=#,If[SameQ@@(Plus@@((#&@@# #[[2]])&/@FactorInteger@#)&/@{#,#+1}&@r),t++];r++];r)&


ลองออนไลน์!


มันต้องการที่จะแสดงผลขนาดใหญ่ของคู่ตามคำอธิบาย; 6ผลตอบแทน714แทน715ตัวอย่างเช่น
numbermaniac

1
@numbermaniac แก้ไขแล้ว! บันทึก 2 ไบต์!
J42161217

2

Pyth, 12 11 ไบต์

e.fqsPtZsPZ

การจัดทำดัชนีจาก 1 จะลบไบต์และวาง Pyth หน้าเจลลี่


คำอธิบาย

e.fqsPtZsPZ - โปรแกรมเต็มรูปแบบ รับอินพุตจากอินพุตมาตรฐาน

ef - องค์ประกอบสุดท้ายของรายการตัวเลข $ แรกที่ป้อนเข้า
   q - เท่ากัน 
    เอสเอส - ผลรวมของ
     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 ตัวตามกฎเริ่มต้น
Mr. Xcoder

@ Mr.Xcoder แน่นอนว่าได้รับการแก้ไขแล้ว
HyperNeutrino



0

Python 2 , 119 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

เครดิตไปที่Dennisสำหรับอัลกอริธึมการแยกตัวประกอบเฉพาะ 1 การจัดทำดัชนี


หมายเหตุ:นี่ช้ามากและไม่มีประสิทธิภาพ อินพุตที่สูงกว่า 7 จะมีปัญหาถ้าคุณไม่ได้ตั้งค่าimport sysและทำsys.setrecursionlimit(100000)แต่ใช้งานได้ในทางทฤษฎี


104 ไบต์โดยการทำfหน้าที่คำนวณหาผลรวมของปัจจัยหลัก
ovs

คงจะดีถ้าคุณติดตามจำนวนไบต์ (และอาจแสดงความคิดเห็นการแก้ไขของคุณ)
ติตัส

(f(n,k+1),k+f(n/k))[n%k<1]อีก -2 ไบต์ สิ่งนี้ทำให้ช้าลง
ovs

-1 ไบต์โดยเปลี่ยนไปi+1 -~i
notjagan
โดยการใช้ไซต์ของเรา หมายความว่าคุณได้อ่านและทำความเข้าใจนโยบายคุกกี้และนโยบายความเป็นส่วนตัวของเราแล้ว
Licensed under cc by-sa 3.0 with attribution required.