Logarithmic Fibonacci ? Sounds Crazy !

Fibonacci sequence is defined as F 0 = 0 , F 1 = 1 F_0=0,F_1=1 and for n 2 n\geq 2 , F n = F n 1 + F n 2 F_n=F_{n-1}+F_{n-2}

Thus, the fibonacci sequence is 0 , 1 , 1 , 2 , 3 , 5 , 8 , 13 , . . . 0,1,1,2,3,5,8,13,...

Find the sum of all the Fibonacci numbers F n F_n less than 1 billion \textbf{1 billion} which follow that log 10 ( F n ) Z \log_{10}(F_n) \in \mathbb{Z}

Details and assumptions :-

F n \bullet \quad F_n denotes n t h n^{th} number in the Fibonacci sequence.

log 10 ( F n ) Z \bullet\quad \log_{10}( F_n) \in \mathbb{Z} means that F n F_n is of the form 1 0 k 10^k for integer value of k k .


This problem is a part of the set Crazy Fibonacci


The answer is 2.

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

David Holcer
Apr 4, 2015
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
from math import *
fib=[0,1]
n=10**9
while fib[-1]<n:
    test=fib[-1]+fib[-2]
    if test<n:
        fib.append(test)
    else:
        break
summ=0
for i in fib:
    try:
        if (log(i)/float(log(10))).is_integer():
            summ+=i
    except(ValueError):
        pass
print summ

Just adding a C++ solution here for the sake of variety ( here ).

Prasun Biswas - 5 years, 10 months ago
Kenny Lau
Aug 29, 2014

Java code:

public class brilliant{
    public static void main(String args[]){
        long previous=-1, current=1, next; //these are the -2th and the -1th term
        long sum=0;
        while(current<1000000000){
            next = previous + current;
            previous = current;
            current = next;
            if(Math.log(current)-((int)(Math.log(current)))==0) sum += current;
        }
        System.out.println(sum);
    }
}

0 pending reports

×

Problem Loading...

Note Loading...

Set Loading...