시간 제한 메모리 제한 제출 정답 맞은 사람 정답 비율
1 초 256 MB 383 159 126 45.818%

문제

Q. : 아래의 수열에서 다음에 올 수를 찾으시오.

313 331 367 ...

경복 : ??

강산 : 379.

경복 : 뭐?

강산 : 행복한 소수잖아.

경복 : 행복한 뭐?

강산 : 그러니까, 자리수의 제곱의 합을 구하는 연산을 계속 반복했을 때 1이 되는 수를 행복한 수라고 하잖아. 행복한 소수는 그 중 소수인 수이고.

7은 분명 소수이다. 과연 행복할까?

  • 7 → 72 = 49
  • 49 → 42 + 92 = 97
  • 97 → 92 + 72 = 130
  • 130 → 12 + 32 + 02 = 10
  • 10 → 12 + 02 = 1

7은 행복한 수이다 ☺.

사실 7은 행복한 소수 중 가장 작은 수이다. (이 문제에서는 1을 소수가 아닌 것으로 생각한다)

어떤 수가 주어지면 이 수가 행복한 소수인지 판정해보자.

입력

첫 줄에 테스트 케이스의 수 P가 주어진다. (1 ≤ P ≤ 1000)

각 테스트 케이스는 테스트 케이스 번호와 행복한 소수인지 판정해야 할 정수인 M으로 이루어져 있다. (1 ≤ m ≤ 10000).

 

출력

각 테스트 케이스마다, 테스트 케이스의 번호, 입력받은 수, 만일 M이 행복한 소수라면 YES 아니라면 NO를 공백으로 각각 구분하여 출력한다.

예제 입력 1

4
1 1
2 7
3 383
4 1000

예제 출력 1

1 1 NO
2 7 YES
3 383 YES
4 1000 NO
W3sicHJvYmxlbV9pZCI6IjEwNDM0IiwicHJvYmxlbV9sYW5nIjoiMCIsInRpdGxlIjoiXHVkNTg5XHViY2Y1XHVkNTVjIFx1YzE4Y1x1YzIxOCIsImRlc2NyaXB0aW9uIjoiPHA+US4gOiBcdWM1NDRcdWI3OThcdWM3NTggXHVjMjE4XHVjNWY0XHVjNWQwXHVjMTFjIFx1YjJlNFx1Yzc0Y1x1YzVkMCBcdWM2MmMgXHVjMjE4XHViOTdjIFx1Y2MzZVx1YzczY1x1YzJkY1x1YzYyNC48XC9wPlxyXG5cclxuPHA+MzEzIDMzMSA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