Professor Laugh's Numbers
Memory limit: 32 MB
Professor Byteman Laugh has been given a unique chance. He has been told that he
could get a million dollars for his research from Foundation for Helping Wicked Byteprofessors.
The professor always does his best to make his research interesting.
Now it is time for the society to grade the professor's work.
However, it is not so easy. The professor has only one week before he will have to present the
results of his research. As every scientist, professor Laugh is a little bit absent-minded.
He has lost the results somewhere, so he is asking you to write a program which reproduces them.
Professor Laugh does not like to bore his friends and colleagues. Therefore,
he is not interested in ordinary integrals, but in thrilling and mind-blowing prime numbers.
For a prime number1
greater than , an integer greater than 1 and an integer less than
the professor says that is -interesting if there is a natural number
such that, In other words and
give the same remainder when divided by .
Task
Write a program which:
- reads a prime number , an exponent and a sequence of numbers;
- tests each number in this sequences if it is -interesting;
- writes the result.
Input
The first line contains two integers separated by a single space: a prime number
and a number (). The second line contains
one integer , i.e. the number of cases ().
Each of next lines contains one integer. The -th of these lines
contains a number , .
Output
Your program should write exactly lines. The line number () should
contain one word: TAK (i.e. yes in Polish) if is -interesting,
NIE (i.e. no in Polish) if it is not.
Example
For the input data:
17 2
5
1
9
3
7
6
the correct result is:
TAK
TAK
NIE
NIE
NIE
1. We say that an integer is prime if it is greater than 1
and it has no positive integer divisors other than 1 and itself.
Task authors: Jakub Pawlewicz, Jakub Radoszewski (formulation by Szymon Wasik).