First 1000 digit Fibonacci number

Project Euler problem 25 is to find the index of the first Fibonacci number of 1000 characters. I used the gmp library – I couldn’t find a way to get the length of a bigz data type so converted it to a string:


digits <- 0
i <- 0

while (digits < 1000) {
    i = i + 1
    number.string = as.character(fibnum(i))
    digits = nchar(number.string)

The gmp fibnum function is quick.

Leave a Reply

Your email address will not be published.