This problem has a cool name

What is the largest integer n < 1000 n<1000 such that the decimal representation of 2 n 2^n does not contain 0 as a digit?

Adapted from a book by J. M. de Koninck.


The answer is 86.

This section requires Javascript.
You are seeing this because something didn't load right. We suggest you, (a) try refreshing the page, (b) enabling javascript if it is disabled on your browser and, finally, (c) loading the non-javascript version of this page . We're sorry about the hassle.

8 solutions

Brock Brown
Jul 1, 2015

Python 3.3:

1
2
3
4
n = 999
while '0' in str(2**n):
    n -= 1
print("Answer:", n)

Nice solution! +1

Arulx Z - 5 years, 11 months ago
Chew-Seong Cheong
Jun 30, 2015

My Python program is as follows:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
for i in range(1000):
    n = 999 - i
    s = str(2**n)
    z = 0
    for j in range(len(s)):
        if s[j] == '0':
            z += 1
        if z == 0:
            print n
            break 

Moderator note:

Good, standard solution.

is there alternative way to do it without Python program ?

Syed Baqir - 5 years, 11 months ago
Arulx Z
Jun 29, 2015
1
2
3
4
5
lar = None
for x in xrange(1, 999):
    if '0' not in str(2**x):
        lar = x
print lar

Moderator note:

Any particular reason to initialize lar to None than zero?

Any idea if there is a larger power of 2 which doesn't contain a 0?

Calvin Lin Staff - 5 years, 11 months ago

Log in to reply

I am sorry but I have no idea on how to find a larger power of two which doesn't contain a 0. I have opened a note here to start a discussion.

Also, there is no specific reason behind why I initialized lar to None .

Arulx Z - 5 years, 11 months ago

Apparently it's an open problem in number theory

Arulx Z - 5 years, 7 months ago
Rushikesh Jogdand
Jun 24, 2016
1
2
3
4
5
index=0
for i in range(0,1001):
    if not '0' in list(set(list(str(2**i)))):
        index=i
print(index)

VB.Net Solution:

Make sure to import System.Numerics.

Sub Main()

    For n = 1000 To 1 Step -1

        If Not ContainsZero(BigInteger.Pow(2, n)) Then

            Console.WriteLine(n)

        End If

    Next

    Console.ReadLine()

End Sub

Function ContainsZero(Number As BigInteger) As Boolean

    Dim a As String = Number.ToString

    For n = 0 To a.Length - 1

        If a(n) = "0" Then

            Return True

        End If

    Next

    Return False

End Function

Thank you for your solution! =D

Pi Han Goh - 5 years, 2 months ago
Rohan Gupta
Jul 21, 2015

My python 2.7 program:
for i in range(1000):
k=2**i
if "0" in str(k):
pass
else:
print i





My colourful layman's solution : y

Bill Bell
Jul 5, 2015

Check for occurrences of zero digits in all powers of two less than one thousand, and avoid exponentiating individual powers of two, which is expensive.

0 pending reports

×

Problem Loading...

Note Loading...

Set Loading...