Project Euler #25: N-digit Fibonacci number

  • + 0 comments
    import sys
    sys.set_int_max_str_digits(6000)
    
    li=[1,1]
    answers=[0,1,]
    x=2
    max_len=1
    
    # I simultaneously calculate the fibonacci numbers and set an answers list corresponding to the nth term which has digits >= that indice of the list
    while max_len<5000:
        x+=1
        new_number=li[-2]+li[-1]
        length=len(str(new_number))
        li.append(new_number)
        if length>max_len:
            answers+=[x]*(length-max_len)
            max_len=length
            
    for _ in range(int(input())):
        n=int(input())
        print(answers[n])