Special series

2

16 votes
Basic Programming, Recursion, Recursion and Backtracking, C++
Problem

Consider a series F that is defined as follows:

  • F(1) = 1
  • F(2) = 1
  • F(3) = 2
  • For n >= 3F(n)2F(n+1)×F(n1)=(1)n

Given two integers n and m. We need to make the nth term and mth term of the series co-prime. Find the largest positive number by which we must divide the nth term and mth term of the series such both terms become co-prime. Since, this number can be very large, print it modulo 109+7.

Note: Two numbers are said to be co-prime if there does not exist any number greater than 1, which divides both the numbers.

Input format

  • The first line contains an integer T denoting the number of test cases.
  • For each test case:
    • The first line contains a string denoting the integer n.
    • The second line contains an integer m.

Output format

For each test case in a new line, find the required largest positive number modulo 109+7.

Constraints

1T1001n101051m109

 

Time Limit: 1
Memory Limit: 256
Source Limit:
Explanation
  • F(3) = 2 and F(6) = 8. If we divide both the terms by 2, then they become co-prime.
  • Thus, 2 is the required answer.
Editor Image

?