Trova l'ennesimo numero Aaron


14

sfondo

Una coppia Ruth-Aaron è una coppia di numeri interi positivi consecutivi ne n+1tale che la somma dei fattori primi (contando i fattori primi ripetuti) di ciascun numero intero è uguale. Ad esempio, (714,715)è una coppia Ruth-Aaron, dal momento che 714=2*3*7*17, 715=5*11*13e 2+3+7+17=5+11+13=29. Il nome della coppia Ruth-Aaron è stato scelto da Carl Pomerance in riferimento al totale della carriera di Babe Ruth714 , che è stato il record mondiale dal 25 maggio 1935 all'8 aprile 1974, quando Hank Aaron ha colpito la sua 715corsa in casa. Puoi saperne di più sull'affascinante storia di questi numeri in questo video di Numberphile .

Obbiettivo

Scrivi un programma o una funzione completa che, dato un numero intero positivo n, genera il nnumero Aaron, dove il nnumero th è definito come il numero intero più grande della ncoppia Th Ruth-Aaron. Quindi il nnumero di Aaron è a(n)+1, dov'è a(n)il ntermine nella sequenza OEIS A039752 .

Casi test

I primi pochi numeri Aaron sono

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

Regole


A dire il vero, "contare la molteplicità" significa che 20 -> 2, 2, 5 non 2, 5 giusto?
HyperNeutrino,

@Okx lo ero, ho appena notato che quando ho aggiornato il suo profilo Youtube, aveva esattamente 1 altro abbonato (non io)
Mr. Xcoder

@HyperNeutrino Sì. Modificherò per rendere più chiaro.
ngenisi,

Possiamo scegliere tra 0 e 1 indicizzazione?
Mr. Xcoder,

3
Anch'io ho visto il video di Numberphile di oggi
shooqie il

Risposte:


7

05AB1E , 11 10 9 byte

-1 byte grazie a Emigna
-1 byte grazie ad Adnan

µN>Ð<‚ÒOË

Spiegazione:

µ            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-indicizzati.

Provalo online!


1
Spiegazione quando puoi, per favore :)
Mr. Xcoder

@ Mr.Xcoder Aggiunto.
Okx,

10 byte:µN>Ð<‚ÒO˽
Emigna il

@Emigna Ah, bello.
Okx,

2
@Adhnan Davvero? Questa è una caratteristica del linguaggio folle.
Okx,

5

Buccia , 11 9 byte

-2 byte grazie a un golf intelligente di @Leo

€∫Ẋ¤=oΣpN

Provalo online!

Spiegazione

  Ẋ     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
Bel lavoro, stavo per pubblicare sostanzialmente la stessa idea :)
Leo


1
@ Leo Ooh, €∫è davvero un bel trucco! E uno che funziona solo in una lingua pigra. ;)
Zgarb

@Leo Molto intelligente.
H.Piz,

3

Pyth , 23 20 byte

Questo è 1-indicizzato.

WhQ=-QqsPZsPhZ=+Z1;Z

Test Suite o provalo online!


Spiegazione

WhQ = -QqsPZsPhZ = + Z1; Z - Programma completo. Riceve input dall'input standard.

WhQ - Mentre Q è ancora superiore a 0.
       sPZ - Somma dei fattori primi di Z.
          sPhZ - Somma dei fattori primi di Z + 1.
      q - Se quanto sopra è uguale:
   = -Q - Decrementa Q di 1 se sono uguali e di 0 se non lo sono.
              = + Z1; - Incrementa Z su ogni iterazione.
                   Z - Uscita Z. 

3

Gelatina , 12 byte

;‘ÆfS€Eµ⁸#Ṫ‘

Un collegamento monadico che prende e restituisce numeri non negativi

Provalo online!

Come?

;‘Æ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)


Ho ancora bisogno della coda.
Jonathan Allan,

1
Ed è quello che ottieni solo per i test 1.
Erik the Outgolfer,

3

PHP, 93 92 91 + 1 byte

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;

Esegui come pipe con -nRo provalo online .

-2 byte con 3 indicizzati (numero Aaron pugno per argomento 3 ): rimuovi 2+.

abbattersi

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 byte

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

1-based. Molto lento.

Provalo online!

Spiegazione

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

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


Provalo online!


Deve produrre il più grande della coppia in base alla descrizione; 6restituisce 714invece di 715, ad esempio.
numbermaniac

1
@numbermaniac fixed! salvato 2 byte!
J42161217

2

Pyth, 12 11 byte

e.fqsPtZsPZ

L'indicizzazione da 1 rimuove un byte e mette Pyth davanti a Jelly


Spiegazione

e.fqsPtZsPZ - Programma completo. Riceve input dall'input standard.

ef - Ultimo elemento dell'elenco dei primi $ numeri di input per i quali
   q - Sono uguali 
    ss - La somma di
     PtZ PZ - Fattori primi di $ numero-1 e $ numero


1

Gelatina , 17 byte

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

Provalo online!

Spiegazione

Æ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-indicizzato


1
Non sono sicuro che l'indicizzazione 2 sia consentita dalle regole predefinite.
Mr. Xcoder,

@ Mr.Xcoder Certo, risolto.
HyperNeutrino,



0

Python 2 , 119 104 102 101 byte

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)

Provalo online!

-17 byte grazie a @ovs!

-1 byte grazie a @notjagan

Il merito va a Dennis per l'algoritmo di scomposizione in fattori primi. 1-indicizzati.


Nota: questo è estremamente lento e inefficiente. Gli input superiori a 7 andranno in crash a meno che tu non lo imposti import syse lo faccia sys.setrecursionlimit(100000), ma funziona in teoria.


104 byte eseguendo funa funzione calcolando la somma dei fattori primi
ovs

Sarebbe bello se seguissi il tuo bytecount (e magari commentassi le tue modifiche).
Tito

(f(n,k+1),k+f(n/k))[n%k<1]per altri -2 byte. Questo lo rende ancora più lento.
Ovs,

-1 byte passando i+1a -~i.
notjagan,
Utilizzando il nostro sito, riconosci di aver letto e compreso le nostre Informativa sui cookie e Informativa sulla privacy.
Licensed under cc by-sa 3.0 with attribution required.