Logo
(追記) (追記ここまで)

8407번 - Professor Laugh's Numbers 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
1 초 128 MB117312027.027%

문제

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 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, xen (mod p). In other words xe 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.

1We say that an integer is prime if it is greater than 1 and it has no positive integer divisors other than 1 and itself.

입력

The first line contains two integers separated by a single space: a prime number p and a number e (3 ≤ p ≤ 232, 2 ≤ e < 232). 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 ni, 1 ≤ nip - 1.

출력

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

제한

예제 입력 1

17 2
5
1
9
3
7
6

예제 출력 1

TAK
TAK
NIE
NIE
NIE

힌트

출처

Contest > Algorithmic Engagements > PA 2006 6-2번

(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /