Fibonacci with GCD

0

0 votes
Grammar-Verified, Open, Recruit, Approved, Grammar-Verified, Open, Recruit, Approved, Grammar-Verified, Segment Trees, Hard, Data Structures, Mathematics, Segment tree, Data Structures
Problem

You are given N integers A1,A2,...,AN and Q queries. In each query, you are given two integers L and R (1LRN).

For each query, write a program to find the value of the following expression:

GCD(F(AL),F(AL+1),F(AL+2)......F(AR))%109+7

Input format

  • First line: Two space-separated integers N and Q
  • Second line: N space-separated integers denoting the elements of array A
  • Next Q lines: Two space-separated integers L and R

Output format

For each query, print the value of the expression.

Note

  • The Fibonacci series is defined as:

    F(N) = F(N1)+F(N2)  N3
    F(1)=1 , F(2)=1

  • The GCD of two numbers is the greatest common divisor of those numbers. For example, GCD(2,4) = 2.

Constraints

1N105
1Q105
1Ai109
1LRN

Time Limit: 2
Memory Limit: 256
Source Limit:
Explanation

For query 1: GCD(F(2) , F(4), F(8))= GCD(1,3,21)=1 For query 2: GCD(F(4), F(8))= GCD(3,21)=3

Editor Image

?