PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#SP0000015. Số nguyên tố hạnh phúc (Happy Happy Prime Prime)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Số nguyên tố hạnh phúc (Happy Happy Prime Prime)

Happy Happy Prime Prime

Source: Kattis

Version: Phuoc Hung OJ Extended

Problem Statement

A positive integer is happy if repeatedly replacing it by the sum of the squares of its decimal digits eventually produces 11. If a value repeats without reaching 11, the process cycles and the original number is unhappy. A happy prime is both an ordinary prime number and a happy number; 11 is not prime. Each data set has an identifier KK and a candidate mm. Determine whether mm is a happy prime.

Input

One line contains two integers KK and mm: the data set identifier and the candidate.

Output

Print one line containing KK, a space, mm, a space, and YES if mm is a happy prime or NO otherwise.

Subtasks

  • Subtask 1 (20 points): 1≤K≤201\le K\le 20, 1≤m≤1001\le m\le 100.
  • Subtask 2 (30 points): 1≤K≤10001\le K\le 1000, 1≤m≤10001\le m\le 1000.
  • Subtask 3 (50 points): 1≤K≤10001\le K\le 1000, 1≤m≤100001\le m\le 10000.

Examples

Input

2 7

Output

2 7 YES

Explanation

The number 77 is prime. Squaring and summing its digits yields 7→49→97→130→10→17\to49\to97\to130\to10\to1, so it is happy. With identifier K=2K=2, print 2 7 YES.

Input

1 1

Output

1 1 NO

Explanation

Although 11 already reaches the happy-state target, it is not prime. The output is therefore 1 1 NO.

Input

3 383

Output

3 383 YES

Explanation

The number 383383 is prime. The successive digit-square sums are 383→82→68→100→1383\to82\to68\to100\to1. Thus both requirements are satisfied and 3 383 YES is printed.