With great F n F_{n} comes great runtime

Let F n F_{n} denotes the n th n^\text{th} Fibonacci number .

Find the sum of odd-digits of F 1000 \displaystyle F_{1000} .

As an explicit example, sum of odd-digits of 128974402103 = 1 + 8 + 7 + 4 + 2 + 0 = 22 128974402103=1+8+7+4+2+0=22


The answer is 508.

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
Jun 2, 2016
1
2
3
4
5
6
fibs=[0,1]
for i in range(1000):
    fibs.append(fibs[-1]+fibs[-2])
x=str(fibs[1000])
ans=sum(ord(x[i])-ord('0') for i in range(0,len(x),2))
print(ans)

@Pranjal Jain , Can you please present a solution in C/C++, I can't make out of this. ( I tried in C, but the time limit was exceeded!)

Kunal Gupta - 4 years, 11 months ago

0 pending reports

×

Problem Loading...

Note Loading...

Set Loading...