# *Trivial* near-repdigit perfect powers

Output the sequence that precisely consists of the following integers in increasing order:

• the 2nd and higher powers of 10 ($$\10^i\$$ where $$\i \ge 2\$$),
• the squares of powers of 10 times 2 or 3 ($$\(2\times 10^i)^2\$$ and $$\(3\times 10^i)^2\$$ where $$\i \ge 1\$$), and
• the cubes of powers of 10 times 2 ($$\(2\times 10^i)^3\$$ where $$\i \ge 1\$$).

First few terms of this sequence look like this:

100, 400, 900, 1000, 8000, 10000, 40000, 90000, 100000,
1000000, 4000000, 8000000, 9000000, 10000000, 100000000, 400000000,
900000000, 1000000000, 8000000000, 10000000000, ...

You can use any of I/O methods:

• Without input, output the sequence infinitely.
• Given $$\n\$$, output the $$\n\$$th number of the sequence (0- or 1-indexed).
• Given $$\n\$$, output the first $$\n\$$ numbers of the sequence.

Standard rules apply. The shortest code in bytes wins.

The section below explains the title, but you don't need to read it to solve the challenge.

## Background

A repdigit is a positive integer whose digits are all the same in base 10. A perfect power is an integer that can be made by raising an integer to the power of 2 or higher, i.e. $$\a^b\$$ where $$\a, b\$$ are integers and $$\b \ge 2\$$.

$$\6^5 = 7776\$$ is an interesting number. It is a perfect power, and it is only 1 away from a repdigit $$\7777\$$. This raises a question: are there any other numbers that are perfect powers and close to a repdigit?

A near-repdigit [1] is a $$\k\$$-digit positive integer such that $$\k \ge 2\$$ and exactly $$\k-1\$$ of the digits are the same. [1] provides the full list of perfect squares that are near-repdigits:

16, 25, 36, 49, 64, 81, 121, 144, 225, 441, 484, 676, 1444, 44944

plus the trivial ones in the form of $$\a \times 100^i\$$, where $$\a\$$ is one of 1, 4, or 9.

[2] provides another result for perfect cubes and higher powers. It shows that, not counting the trivial ones $$\10^i\$$ and $$\8 \times 1000^i\$$, the list of near-repdigit perfect powers for any specific exponent is finite. (Note that this does not imply that the list of nontrivial such numbers as a whole is finite; to the best of my knowledge, it is an open question.) I ran my program up to $$\10^{24}\$$ but did not find any non-square ones except 27, 32, 343, 7776.

The following is the list of all near-repdigit perfect powers up to $$\10^{10}\$$.

16, 25, 27, 32, 36, 49, 64, 81, 100, 121, 144, 225, 343, 400, 441, 484,
676, 900, 1000, 1444, 7776, 8000, 10000, 40000, 44944, 90000, 100000,
1000000, 4000000, 8000000, 9000000, 10000000, 100000000, 400000000,
900000000, 1000000000, 8000000000, 10000000000

[1] A. Gica and L. Panaitopol, On Oblath’s problem

[2] O. Kihel and F. Luca, Perfect Powers With All Equal Digits But One

# JavaScript (Node.js), 53 bytes

Try it online!

-2 from Arnauld

-1 from Tbw

• why 2.52? can it not be 2.5?
– Tbw
Commented May 9 at 8:01
• @Tbw Something must went wrong when searching
– l4m2
Commented May 9 at 8:09
• its funny I keep discovering improvements then looking back and seeing that you found them too
– Tbw
Commented May 9 at 8:15
• 51 bytes
– Tbw
Commented May 9 at 8:28
• 53 alternate
– l4m2
Commented May 10 at 8:41

# Pyth, 26 bytes

KT#=*KTj*LKf!%lPK%T5j1489T

Try it online!

Outputs the infinite sequence.

### Explanation

KT                            # assign K = 10
#                           # enter infinite loop
=*KT                       #   assign K = K * 10
j1489T    #   list [1, 4, 8, 9]
f                  #   filter list on lambda T
lPK             #     length of the list of prime factors of K
%   %T5          #     modulo (T % 5)
!                 #     true if 0
*LK                   #   map list over multiplication by K
j                      #   print list joined on newlines

# Charcoal, 37 bytes

ＮθＩ…ΦＥ⊗θ×Ｉ§1489ιＸχ⁺²÷ι⁴¬﹪⊖Ｌι⁻³↔⁻²﹪κ⁴θ

Try it online! Link is to verbose version of code. Explanation:

Ｎθ                                      Input n as an integer
θ                                Input n
⊗                                 Doubled
Ｅ                                  Map over implicit range
1489                         Literal string 1489
§                             Cyclically indexed by
ι                        Current value
Ｉ                              Cast to string
×                               Multiplied by
χ                      Predefined variable 10
Ｘ                       Raised to power
²                    Literal integer 2
⁺                     Plus
ι                  Current value
÷                   Integer divided by
⁴                 Literal integer 4
Φ                                   Filtered where
ι            Current value
Ｌ             Length
⊖              Decremented
¬﹪               Is divisible by
³          Literal integer 3
⁻           Subtract
²       Literal integer 2
↔⁻        Absolute difference with
κ     Current index
﹪      Modulo
⁴    Literal integer 4
…                                 θ   Take the first n terms
Ｉ                                     Cast to string
Implicitly print

Using the method of @l4m2's JavaScript solution to output the first n terms is also 37 bytes:

ＩＥＮ×Ｉ§”)¶k✳ï↑;¹”ιＸχ⁺×³÷ι⁷Ｉ§”)⊞∨+γ⊗<”ι

Try it online! Link is to verbose version of code. Explanation:

Ｎ                             Input n as a number
Ｅ                              Map over implicit range
”...”                     Compressed string 14918149114891
§                          Cyclically indexed by
ι                    Current index
Ｉ                           Cast to integer
×                            Multiplied by
χ                  Predefined variable 10
Ｘ                   Raised to power
³               Literal integer 3
×                Multiplied by
ι             Current index
÷              Integer divided by
⁷            Literal integer 7
⁺                 Plus
”...”     Compressed string 22233441233334
§          Cyclically indexed by
ι    Current index
Ｉ           Cast to integer
Ｉ                               Cast to string
Implicitly print

# 05AB1E, 25 20 bytes

∞¦°εŽ5×SDyÒgs5%ÖÏ*}˜

-5 bytes porting @CursorCoercer's Pyth answer, so make sure to upvote that answer as well!

Outputs the infinite sequence.

Try it online.

∞<°2Å€ƵmS*}3Å€¸˜¬8*ª{}¦¦˜

Outputs the infinite sequence.

Try it online.

A port of @l4m2's alternative JavaScript approach is 25 bytes as well:

•A¨Ý›¹ •∞èεN6*46+y-14÷<°*

Outputs the infinite sequence.

Try it online.

Explanation:

∞               # Push an infinite positive list: [1,2,3,...]
¦              # Remove the leading 1: [2,3,4,...]
°             # Take 10 to the power each: [100,1000,10000,...]
ε               # Map each to:
Ž5×            #  Push compressed integer 1489
S           #  Convert it to a list of digits: [1,4,8,9]
D          #  Duplicate it
y         #  Push the current power of 10 value
Ò        #  Pop and get its prime factors
g       #  Pop and push the length
s      #  Swap so the duplicated [1,4,8,9] is at the top
5%    #  Modulo-5 each
Ö   #  Check whether the amount of prime factors is divisible by [1,4,8,4]
Ï  #  Only keep the digits from list [1,4,8,9] at the truthy positions
* #  Multiply each to the current power of 10 value
}˜              # After the map: flatten the list of lists
# (after which the infinite list is output implicitly as result)
∞               # Push an infinite positive list: [1,2,3,...]
<              # Decrease each by 1 to make it a non-negative list: [0,1,2,...]
°             # Take 10 to the power each: [1,10,100,1000,...]
2Å€    }     # Map every 2nd value (index%2==0) to:
Ƶm        #  Push compressed integer 149
S       #  Convert it to a list of digits: [1,4,9]
*      #  Multiply each digit to the current value
3Å€       }  # Then map every 3rd value (index%3==0) to:
¸˜        #  Wrap into a list and flatten (e.g. 1000 becomes [1000] and
#  [1000000,4000000,9000000] remains unchanged)
¬       #  Get the first item of this list (without popping)
8*     #  Multiply it by 8
ª    #  Append it to the list
{   #  Sort it (to fix the order of the values starting with 9,8)
¦¦           # Then remove the first two values ([1,4,8,9] and 10)
˜          # Flatten
# (after which the infinite list is output implicitly as result)
•A¨Ý›¹ •        # Push compressed integer 11491814911489
∞       # Push an infinite positive list: [1,2,3,...]
è      # 0-based modular index into the earlier integer: [1,4,9,...]
ε               # Then map over each digit:
N              #  Push the current 0-based map-index
6*            #  Multiply it by 6
y-       #  Subtract the current digit
14÷    #  Integer-divide it by 14
<   #  Subtract that by 1
°  #  Take 10 to the power that
* #  Multiply it to the current digit
# (after which the infinite list is output implicitly as result)

See this 05AB1E tip of mine (section How to compress large integers?) to understand why Ž5× is 1489; Ƶm is 149; and •A¨Ý›¹ • is 11491814911489.

# APL+WIN, 46 bytes

Prompts for number of terms:

n↑1↓m[⍋m←∊((↑¨m)*3),((m←i×¨⊂2 3)*2),i←10*⍳n←⎕]

Try it online! Thanks to Dyalog Classic

# Vyxal, 18 bytes

⇧ɾ↵:₌vTd:3e‟"²Wfsi

Try it Online!

A silly little answer. 1-indexed, outputs the nth item.

## Explained

⇧ɾ↵:₌vTd:3e‟"²Wfsi­⁡​‎‎⁪⁡⁪⁠⁪⁡⁪‏⁠‎⁪⁡⁪⁠⁪⁢⁪‏‏​⁡⁠⁡‌⁢​‎‎⁪⁡⁪⁠⁪⁣⁪‏‏​⁡⁠⁡‌⁣​‎‎⁪⁡⁪⁠⁪⁤⁪‏‏​⁡⁠⁡‌⁤​‎‎⁪⁡⁪⁠⁪⁢⁡⁪‏⁠‎⁪⁡⁪⁠⁪⁢⁢⁪‏⁠‎⁪⁡⁪⁠⁪⁢⁣⁪‏⁠‎⁪⁡⁪⁠⁪⁢⁤⁪‏‏​⁡⁠⁡‌⁢⁡​‎‎⁪⁡⁪⁠⁪⁣⁡⁪‏⁠‎⁪⁡⁪⁠⁪⁣⁢⁪‏⁠‎⁪⁡⁪⁠⁪⁣⁣⁪‏‏​⁡⁠⁡‌⁢⁢​‎‎⁪⁡⁪⁠⁪⁣⁤⁪‏‏​⁡⁠⁡‌⁢⁣​‎‎⁪⁡⁪⁠⁪⁤⁡⁪‏⁠‎⁪⁡⁪⁠⁪⁤⁢⁪‏‏​⁡⁠⁡‌⁢⁤​‎‎⁪⁡⁪⁠⁪⁤⁣⁪‏‏​⁡⁠⁡‌⁣⁡​‎‎⁪⁡⁪⁠⁪⁤⁤⁪‏⁠‎⁪⁡⁪⁠⁪⁢⁡⁡⁪‏‏​⁡⁠⁡‌⁣⁢​‎‎⁪⁡⁪⁠⁪⁢⁡⁢⁪‏‏​⁡⁠⁡‌­
⇧ɾ                  # ‎⁡range [1, n + 2]
↵                 # ‎⁢10 ^ x for x in the above
:                # ‎⁣duplicate, and
₌vTd            # ‎⁤Triple each item, and double each item, separately
:3e         # ‎⁢⁡duplicate the double list, and cube each value
‟        # ‎⁢⁢rotate the stack right so that the triple and double lists are back on top
"²      # ‎⁢⁣pair into a single list and square each item
W     # ‎⁢⁤Wrap the entire stack into a list. This gives [cubes of 2*10^n, 10^n list, squares of [3*10^n, 2*10^n]]
fs   # ‎⁣⁡flatten and sort that. Note that this includes 10 at the start, which is 10^1.
i  # ‎⁣⁢which is why the output is 1-indexed :p. Get the n-th item, 0-indexed, but n = 1 skips over the edge case of 10^1.
💎

Created with the help of Luminespire.

# Vyxal 3, 17 bytes

…ɾĖ:∥ᵛTd∥3*;²WfSi

Try it Online!

Uses the latest technology of arity grouping and properly implemented parallel apply. Ports my Vyxal 2 answer.

# TI-BASIC, 64 bytes

Input T
For(I,1,T
₁₀^(I→P
8P³→L₁(1+dim(L₁
augment(L₁,augment(seq(J²P²,J,2,3),{10P→L₁
End
SortA(L₁
L₁(T

This calculates the sequence, sorts it (the calculation generates the correct numbers but in the wrong order), and outputs the requested number of the sequence.

Here is an example with an input of 3. The output is 900 (yes, it's 1-indexed):

# Python 3, 110 bytes

n=int(input());k=lambda x,y:[x*(10**y)**i for i in range(1,n+1)];print(sorted(k(1,1)+k(4,2)+k(8,3)+k(9,2))[n])

Try it online!

This answer is a bit long, let me know if it can be improved.

Queries the n-th term prompted by input, 1-indexed.

This first generates the sequence in wrong order and then sorts it.

# Perl 5-Mbigint -p, 71 bytes

$_=(sort{(log$a)-log$b}map{$z=10**$_,4*$z**2,9*$z**2,8*$z**3}1..$_)[$_]

Try it online!

Takes n as an input and output's the n-th item in the sequence, 1-indexed.

# Pip, 27 bytes

W PtPB0P*t*Y489FE1=#t%Y%_+2

Outputs infinitely. Attempt This Online!

### Explanation

This is an interesting challenge. I'm far from certain that this is the golfiest approach possible.

W PtPB0P*t*Y489FE1=#t%Y%_+2
; t is initially 10
W                            ; While this value is truthy...
tPB0                      ;   Append a 0 to t (i.e. multiply it by 10)
P                          ;   Print and return it
; ... loop:
; (t will always be nonzero and therefore truthy)
489FE            ;   Filter the digits of 489 based on a function of their
;   indices (0, 1, 2):
%_    ;     Index mod 2 (0, 1, 0)
+2  ;     plus 2 (2, 3, 2)
#t        ;     Length of t (1 more than the power of 10 that t is)
%Y      ;     Take the length mod the 2, 3, or 2 from above
1=          ;     Is the result equal to 1?
t*Y                 ;   Multiply the digits that remain by t
P*                    ;   Print each of the results