Sequences

4.2

17 votes
Easy, Basic Math, Mathematics, Mathematics
Problem

You are given a function that is similar to the Fibonacci series.

The function f is represented as follows: 

f(1)=a,f(2)=b,f(i)=f(i1)+f(i2) for integer i3

You do not know the numbers that are available in the sequence. You are also given q queries. Each query contains a number x. Your task is to determine whether a positive ith integer satisfies f(i)=x.

Input format

  • First line: Two integers a, b (0a,b1018)
  • Second line: An integer q (0q106)
  • Each of the q lines: An integer xi (0xi1018)

Output format

Print the answer for each of the q queries in a new line. Therefore, the output must contain q lines. Print YES if there is an integer that satisfies the condition. Otherwise, print NO.

 

Time Limit: 1
Memory Limit: 256
Source Limit:
Explanation

F=1 1 2 3 5 8 13 21 ...

Editor Image

?