Professor Laugh's Numbers
Time limit1sMemory limit128 MB
Given a prime p, exponent e, and queries n, decide whether n is an e-th power residue modulo p.
- Level
Medium7 of 10
- Topics
- Number theory, Math, Binary search, Divide and conquer
- Solved
- No attempts yet
Problem
Professor Byteman Laugh studies prime numbers.
For a prime , an integer , and an integer with , we say that is -interesting if there exists a natural number such that that is, and leave the same remainder when divided by .
Write a program that reads a prime , an exponent , and a sequence of numbers, and then decides for each number whether it is -interesting.
Input
The first line contains two integers separated by a single space: a prime number and an exponent (, ).
The second line contains one integer , the number of queries ().
Each of the next lines contains one integer ().
Output
Print exactly lines. Line () must contain a single word: TAK (yes) if is -interesting, or NIE (no) otherwise.