• + 1 comment

    Working Python3 solution

    P = 10 ** 9 + 7
    
    from fractions import gcd
    from functools import reduce, lru_cache
    
    @lru_cache(maxsize = None)
    def fib(n):
        if n == 0:
            return 0
        if n == 1:
            return 1
        if (n & 1) == 1:
            return (fib(n // 2) * fib(n // 2) + fib(n // 2 + 1) * fib(n // 2 + 1)) % P
        else:
            return fib(n // 2) * (fib(n // 2) + 2 * fib(n // 2 - 1)) % P
    
    n = int(input())
    a = (int(input()) for _ in range(n))
    g = reduce(gcd, a, 0)
    print(fib(g))