QOJ.ac

QOJ

Time Limit: 1 s Memory Limit: 32 MB Total points: 10

#11658. Professor Laugh's Numbers

统计

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 number^{1} $ p $ greater than 2, an integer $ e $ greater than 1 and an integer $ n $ less than $ p $ the professor says that $ p $ is $(p, e)$ -interesting if there is a natural number $ x $ such that, $ x^{e} \equiv n \pmod p$. In other words $ x^{e} $ and $ n $ give the same remainder when divided by $ p $.

Write a program which:

  • reads a prime number $ p $, an exponent $ e $ and a sequence of numbers;
  • tests each number in this sequences if it is $(p, e)$-interesting;
  • writes the result.

^{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.

Input Format

The first line contains two integers separated by a single space: a prime number $ p $ and a number $ e $ ($3 ≤ p ≤ 2^{32}$, $2 ≤ e < 2^{32}$). The second line contains one integer $ k $, i.e. the number of cases ($1 ≤ k ≤ 15$). Each of next $ k $ lines contains one integer. The $ i $-th of these lines contains a number $ n_{i} $, $1 ≤ n_{i} ≤ p - 1$.

Output Format

Your program should write exactly $ k $ lines. The line number $ i $ ($1 ≤ i ≤ k $) should contain one word: TAK (i.e. yes in Polish) if $ n_{i} $ is $(p, e)$-interesting, NIE (i.e. no in Polish) if it is not.

Example

Input

17 2
5
1
9
3
7
6

Output

TAK
TAK
NIE
NIE
NIE

Discussions

About Discussions

The discussion section is only for posting: Editorials, General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues. Submitting multiple issues may cause your account to be banned.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.