How Many 8's?

Let x n x_n be defined as the smallest positive integer satisfying x n 3 888 8 n 8’s ( m o d 1 0 n ) . \large x_n ^3 \equiv \underbrace{888\ldots 8}_{n \text{ 8's}} \pmod{10^n} .

Find 1 2 n = 1 8 x n \displaystyle \dfrac12 {\sum_{n=1}^{8} x_n} .

Hint : x 1 = 2 x_1=2 and x 2 = 42 x_2=42 . The answer is a prime number as well.


Inspiration .


The answer is 6617473.

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.

2 solutions

Sam Bealing
Jun 22, 2016

I have used Mathematica code to get the solution:

1
2
3
4
Do[s = Table[8, {d}];
 i = Ceiling[(10^(d - 1))^(1/3)]; 
While[! (IntegerDigits[i^3][[-d ;; -1]] == s), i++]; 
 Print[i], {d, 1, 8}]

This gives the values of x n x_n as: 2 , 42 , 192 , 1942 , 1942 , 76942 , 1576942 , 11576942 2, 42, 192, 1942, 1942, 76942, 1576942, 11576942 .

Their sum is 13234946 13234946 which divided by 2 2 is 6617473 \color{#20A900}{\boxed{\boxed{6617473}}} which incidently is prime.

Moderator note:

What would the number theoretic approach yield?

This is one instance in which the CS approach quickly yields the result, but doesn't offer much more insight into the pattern.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include<bits/stdc++.h>
using namespace std;

unsigned long long eightnew(int n)
{
     unsigned long long i,a=(ceil(pow(10,n))-1)*8/9,b=ceil(pow(10,n)),k;
    for(i=2;;i+=10)
    {
        k=i*i*i;
        k=k%b;
        if(k==a)return i;
    }
}
int main()
{
    long long s=0;
    for(int n=1;n<=8;n++)
    {
    s+=eightnew(n);
    }
    cout<<s/2<<endl;
}

bro, can you help? i don't find any fault in my code.

fahim saikat - 4 years, 11 months ago

Log in to reply

When i > 1 0 7 i 3 > 1 0 21 i \gt 10^{7} \Rightarrow i^{3} > 10^{21} , which exceeds the maximum that can be stored in unsigned long long int (almost 10^20). You should change k = i * i * i; k %= b to k = (((i * i) % b) * i). This will yield the correct output.

Krutarth Patel - 4 years, 11 months ago

Log in to reply

o tnx@ Krutarth Patel

fahim saikat - 4 years, 11 months ago

As Calvin points out, a number-theoretic approach to this problem provides a more efficient solution. Here's one that I implemented:

Define P ( n ) : = { x x 3 88 88 n times ( m o d 1 0 n ) } P(n):=\{x\mid x^3\equiv\underbrace{88\ldots 88}_{n\textrm{ times}}\pmod{10^n}\} .

First, we note two things:

1) a P ( n ) a P ( n 1 ) n 2 a\in P(n)\implies a\in P(n-1)~\forall~n\geq 2 (obvious)

2) n 1 , a P ( n ) 0 < a 1 0 n P ( n ) = \forall~n\geq 1~,~a\notin P(n)~\forall~0\lt a\leq 10^n\implies P(n)=\emptyset (since x m ( x m o d 1 0 n ) ( m o d 1 0 n ) x^m\equiv (x~\bmod~10^n)\pmod{10^n} )

Combining these two things, we can see that finding P ( 1 ) P(1) is easy by just testing the values less than 10 10 and n 1 \forall~n\geq 1 , after finding P ( n ) P(n) , to find P ( n + 1 ) P(n+1) , we just need to test the values a a which are < 1 0 n \lt 10^n and a m o d 1 0 n P ( n ) a~\bmod~10^n\in P(n) . If no solutions are found in a particular iteration, that means no further solutions exist.

So, we implement this in python as follows (using res for P ( n ) P(n) and resn for P ( n + 1 ) P(n+1) )

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
from itertools import count                                 #non-negative integer generator
def test(x,m,a,n):                                          
    return pow(x,m,10**n)==int(str(a)*n)                    #x^m = a (mod 10^n) test

def method(a,m,s):                                          #a is 1-digit and method prints the smallest solutions to x^m = a (mod 10^n) for n=1 to s
    res=[i for i in range(10) if test(i,m,a,1)]; resn=[]    #res is the old solution basis and resn is the new solution basis
    if res==[]:                                             #old solution basis is empty, so no (further) solutions possible
        print('No solutions possible')
        return
    else: print(res[0])                                     #else res[0] is the minimum solution when n=1
    for n in range(2,s+1):                                  #loop for s solutions, is executed when s>1
        for i in res:
            for p in count():
                xn=int(str(p)+str(i))                       #possible solution generated from old solution basis res
                if xn>=10**n: break                         #values xn greater than modulo are solutions iff xn mod 10**n is a solution, so no need to test bigger values, so break
                if test(xn,m,a,n): resn.append(xn)          #if it's a solution, append it to resn, the new solution basis for next iteration
        if resn==[]:
            print('No further solutions possible, all %d solutions generated' %(n-1))
            return
        else:
            res=resn[:]                                     #copy resn to res for next iteration basis
            print(min(res))                                 #print the smallest solution found in current iteration
            resn=[]                                         #clear resn for next iteration

method(8,3,8)                                               #call to method for first 8 solutions to x^3 = 88..88 (n times)  (mod 10^n)

In fact, the above code provides an efficient (more or less) solution to a more general problem, i.e., method(a,m,s) solves the problem of finding the smallest positive integer solutions to ( x n ) m a a a a n times ( m o d 1 0 n ) 1 n s (x_n)^m\equiv\underbrace{aa\ldots aa}_{n\textrm{ times}}\pmod{10^n}~\forall~1\leq n\leq s where 1 a 9 1\leq a\leq 9 and m 1 m\geq 1 .

Prasun Biswas - 4 years, 11 months ago
Rushikesh Jogdand
Jun 25, 2016

Brute force. There is a method in modulus' mathematics but that is, well, rigorous.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
def f(n):
    k=2
    s=''
    for i in range(n):
        s+='8'
    while True:
        if str(k**3%(10**(n)))==s:
            return k
        k+=2
su=0
for i in range(1,9):
    su+=f(i)
print(su/2)

You indented the k+=2 line wrong. The code, as it is now, goes into an infinite loop in the while True: part when f(2) is called.

Prasun Biswas - 4 years, 11 months ago

Log in to reply

Thanks., corrected!

Rushikesh Jogdand - 4 years, 11 months ago

Thanks., corrected!

Rushikesh Jogdand - 4 years, 11 months ago

0 pending reports

×

Problem Loading...

Note Loading...

Set Loading...