A trigonometry function

2.6

17 votes
Basic Math, C++, Math
Problem

You are given a function f(n)=2×7n/2×cos(nθ)+n×4n, where θ=tan132.

You are also given two integers p and q. Your task is to find the value of n=qn=pf(n) (modulo 109+21).

Input format

  • The first line consists of an integer T denoting the number of test cases.
  • Each of the next T lines consists of two space-separated integers p and q.

Output format

Print T lines each containing a single integer corresponding to the required value n=qn=pf(n). Print the answer modulo 109+21.

Constraints

1T1020pq1018

Time Limit: 0.5
Memory Limit: 256
Source Limit:
Explanation

f(0)=2f(1)=8S=f(0)+f(1)=10

Editor Image

?