Fibonnaci Palindrome

Consider concatenating the first n n Fibonacci integers into a continuous integer. For example, for n = 7 n=7 the string would be F 7 = 11235813 F_7 = 11235813 Let S S be the smallest palindrome greater than F 100 F_{100} . What are the last three digits of the sum of the digits of S S .


The answer is 581.

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.

1 solution

Pranjal Jain
Apr 9, 2015

First of all, I defined a function F F which returns the concatenated string.

1
2
3
4
5
6
7
8
def F(x):
    lista=[]
    a=0
    b=1
    for i in range(0,x):
        lista.append(str(b))
        a,b=b,a+b
    return lista

Now, since we want the smallest palindrome, I replaced the later half of the list by the former half.

1
2
3
4
cd=F(100)
len(cd)   # Returns 1071
for i in range(0,535):
    cd[1070-i]=cd[i]

Now I compared the cd with F(100) ,

1
cd>F(100) # Returns False

Thus, the list cd is maximum palindrome smaller than F100

Hence, we'll increase the middle digit by 1 1 ,

1
sum(cd) #Returns 4580

Adding 1 1 to middle digit would make it 4581

I just now realized that middle digit could have been 9 9 , but I'm not so unfortunate...

Pranjal Jain - 6 years, 2 months ago

Log in to reply

Good job. Can you come up with an algorithm ?

Thaddeus Abiy - 6 years, 2 months ago

0 pending reports

×

Problem Loading...

Note Loading...

Set Loading...