Echo numbers (A383896) are positive integers k such that the largest prime factor of k-1 is a suffix of k.
example
k = 4971 is an Echo number because k-1 = 4970 = 2*5*7*71 and k ends in 71
Here are the first Echo numbers:
13, 57, 73, 111, 127, 163, 193, 197, 313, 323, 337, 419, 433, 687, 757, 817, 847, 897, 929, 931, 973...
Input
A positive integer n
Output
The n-th Echo Number or the first n Echo numbers
n -> n-th Echo number
1 -> 13
10 -> 323
101 -> 17191
1015 -> 692231
10158 -> 23421249
0 or 1 indexed is allowed, just specify which one your code uses.
This is Code-Golf: shortest answer in bytes wins!
-
2\$\begingroup\$ Can we return a lazy enumerator/generator that yields the sequence, as in the default sequence rules? \$\endgroup\$Jordan– Jordan2025年05月19日 19:55:13 +00:00Commented May 19 at 19:55
-
1\$\begingroup\$ @Jordan yes, you can \$\endgroup\$ZaMoC– ZaMoC2025年05月19日 20:15:32 +00:00Commented May 19 at 20:15
17 Answers 17
JQ, 112 bytes
1|recurse(.+1)|select(. as$b|"\(.)"|test($b-1|last(recurse(. as$a|./first(range(2;.)|select($a%.<1))))|"\(.)$"))
Racket, 196 bytes
(require math/number-theory)
(define(f n[i 3])(let([k(+ i 1)][e(car(last(factorize(- i 1))))])(if(= 0 n)'()(if(= 0(modulo(- i e)(expt 10(ceiling(/(log e)(log 10))))))(cons i(f(- n 1)k))(f n k)))))
Returns the first n echo numbers.
TIO doesn't seem to recognize (log z [b]) and that's why I used (/ (log z) (log b)) instead. The suffix matching could most probably be done nuch shorter with regex.
Jelly, 12 bytes
DḌÐƤf’ÆfṪƊƲ#
A full program that accepts the count, \$n\$, from stdin and prints the first \$n\$ echo numbers.
How?
DḌÐƤf’ÆfṪƊƲ# - Main Link: no arguments
# - start at k=0 and count up finding the first {stdin} k for which:
Ʋ - last four links as a monad - f(k):
D - decimal digits of {k}
ḌÐƤ - convert suffixes of {that} from decimals to integers
Ɗ - last three links as a monad - f(k):
’ - decrement {k}
Æf - prime factors
Ṫ - tail (maximal)
f - {suffix integers} filter keep {maximal prime factor of k-1}
- implicit print
Ruby, 56 bytes
-10 bytes thanks to Value Ink
Prints the sequence indefinitely.
i=2
loop{p i if/#{i.prime_division[-1][0]}$/=~"#{i+=1}"}
-
1\$\begingroup\$ Since infinite printing is allowed in the sequence rules you can do Ruby, 56 bytes:
i=2;loop{p i if/#{i.prime_division[-1][0]}$/=~"#{i+=1}"}\$\endgroup\$Value Ink– Value Ink2025年05月23日 00:44:44 +00:00Commented May 23 at 0:44 -
\$\begingroup\$ @ValueInk Nice. Thanks! \$\endgroup\$Jordan– Jordan2025年05月23日 01:42:35 +00:00Commented May 23 at 1:42
JavaScript (V8), 76 bytes
Prints the sequence indefinitely.
for(k=9;++k;)(g=x=>x>1?g(x%d++?x:x/--d):k+g)(k-1,d=2).match(d+"x")&&print(k)
JavaScript (ES6), 79 bytes
Returns the \$n\$-th term of the sequence, 1-indexed.
f=(n,k)=>!(g=x=>x>1?g(x%d++?x:x/--d):k+g)(k-1,d=2).match(d+"x")||n--?f(n,-~k):k
Commented
f = ( // f is a recursive function taking:
n, // n = input
k // k = counter, initially undefined
) => //
!( //
g = x => // g is a recursive function taking x:
x > 1 ? // if x is greater than 1:
g( // do a recursive call to g:
x % d++ ? // if d is not a divisor of x
// (increment d afterwards):
x // leave x unchanged
: // else:
x / --d // restore d and divide x by d
) // end of recursive call
: // else:
k + g // return k, converted to a string with
) // a suffix starting with "x"
(k - 1, d = 2) // initial call to g with k - 1 and d = 2
.match(d + "x") // if d is not a suffix of k
|| n-- ? // or n is not 0 (decrement it afterwards):
f(n, -~k) // try again with k + 1
: // else:
k // stop and return k
05AB1E, (削除) 9 (削除ここまで) 8 bytes
∞ʒD<fθÅ¿
Outputs a lazy infinite list.
Explanation:
∞ # Push an infinite positive list: [1,2,3,...]
ʒ # Filter this list by:
D # Duplicate the current value
< # Decrease the copy by 1
f # Pop and push a list of its prime factors
θ # Pop and leave the last/maximum value
# (for n=1 or n=2, the list is empty, and this will be a no-op)
Å¿ # Check whether the value has this maximum prime factor as prefix
# (which will be falsey for the empty lists of n=1 or n=2)
# (after which the infinite lazy list is output implicitly)
Uiua 0.17.0-dev.1, (削除) (削除ここまで) 28 bytes SBCS
⍥(+1.⍢+1(×ばつ-1.))⊙3
Takes \$n\$ on the stack and outputs an array with the first \$n\$ terms.
Explanation
⍥(+1.⍢+1(×ばつ-1.))⊙3
⊙3 # Starting at 3
⍥ # do the following n times...
(×ばつ-1.)# test if n is NOT an echo numbe×ばつ-1. # factor n-1
⊣ # last factor
∩°⋕ # stringify both
∩⇌ # reverse both
⌕ # find occurances
¬⊢ # !(first element)
⍢+1 # add 1 while TRUE
+1. # leave result on stack, add 1, start over
Retina, 69 bytes
K`9
"$+"{/(.+)¶1円$/^{L$`^.+
$.(*__)¶$&*
+`¶(__+)1円+$
¶1ドル
)`_+
$.&
G`^
Try it online! Outputs the 1-indexed nth number. Explanation:
K`9
Start with k=9.
"$+"{`
Repeat n times.
L$`^.+
$.(*__)¶$&*
Increment k, then follow it with the new k-1 in unary.
+`¶(__+)1円+$
¶1ドル
Find the largest prime factor of k-1.
_+
$.&
Convert it back to decimal.
/(.+)¶1円$/^`{
)`
Repeat until k ends with that prime factor. (The inner loop automatically restarts because the prime factor was removed on the previous iteration of the outer loop.)
G`^
Remove the prime factor.
Charcoal, 39 bytes
NθW‹jθ«≦⊕χ¿¬⌕⮌Iχ⮌I⊟Φ...2χ∧¬%⊖χκ⬤...2κ%κμ⟦Iχ
Try it online! Link is to verbose version of code. Outputs the first n numbers. Explanation:
Nθ
Input n.
W‹jθ«
Repeat until n numbers have been output.
≦⊕χ
Increment k, using the variable that is predefined to the value 10.
¿¬⌕⮌Iχ⮌I⊟Φ...2χ∧¬%⊖χκ⬤...2κ%κμ
Find all factors of k-1, filter on those that are prime, take the largest, and see wither k ends with it.
⟦Iχ
If so then output k.
Pyth, 13 bytes
.f!x_`Z_`&FPt
Outputs the first n numbers.
Explanation
.f!x_`Z_`&FPtZQ # implicitly add ZQ
# implicitly assign Q = eval(input())
.f Q # return the first Q integers that are truthy in lambda Z
tZ # Z - 1
P # prime factors as a sorted list
&F # take the last element (unless list is empty, then return [])
_` # stringify and reverse
x_`Z # find within Z stringified and reversed
! # not (is truthy only when result is 0)
Vyxal 3, 15 bytes
kNʎ‹K~℗G⇄n⇄Pc}i
There's probably a better way to check for suffixes than this but i can't figure it out. My lack of sleep doesn't help.
kNʎ‹K~℗G⇄n⇄Pc}i
i # index implicit input in list
kN # natural numbers
ʎ } # filtered by...
‹ # is n-1's
K~℗G # biggest prime factor
⇄n⇄Pc # a suffix of n?
💎
Created with the help of Luminespire.
<script type="vyxal3">
kNʎ‹K~℗G⇄n⇄Pc}i
</script>
<script>
args=[["0"],["1"],["2"],["3"]]
</script>
<script src="https://themoonisacheese.github.io/snippeterpreter/snippet.js" type="module"/>
TI-BASIC (TI-83 Plus), 115 bytes
not my proudest one.
Input I
1→O
While I
O+2→O
O-1→N
For(A,N-1,2,-1
N/A→Z
If not(fPart(Z
Then
sum(not(fPart(seq(Z/B,B,2,Z→C
If C=1
Z→U
End
End
If sum(seq(U=10^(E)fPart(O/10^(E)),E,1,1+log(O
Then
Disp O
I-1→I
End
End
Keep in mind this is EXTREMELY SLOW.
this is 1-indexed
Python, 259 bytes
Golfed version. Try It Online!
def C(n):
B=[];A=2
while n>1:
while n%A==0:B.append(A);n=n//A
A+=1
return B
def D(factors):
A={}
for B in factors:A[B]=A.get(B,0)+1
return A
A=10
while True:
E=C(A-1);F=D(E);B=False
for(H,G)in F.items():
if G==A:B=True;break
if B:print(A)
A+=1
Ungolfed version. Try It Online!
def get_prime_factorization(n):
"""Get prime factorization of n as a list of factors"""
factors = []
divisor = 2
while n > 1:
while n % divisor == 0:
factors.append(divisor)
n = n // divisor
divisor += 1
return factors
def count_factor_occurrences(factors):
"""Count occurrences of each factor"""
counts = {}
for factor in factors:
counts[factor] = counts.get(factor, 0) + 1
return counts
# Main loop starting from k = 10
k = 10
while True:
factors = get_prime_factorization(k - 1)
factor_counts = count_factor_occurrences(factors)
# Check if any factor appears exactly k times
found = False
for factor, count in factor_counts.items():
if count == k:
found = True
break
if found:
print(k)
k += 1