#SP0000015. Số nguyên tố hạnh phúc (Happy Happy Prime Prime)
Bài tập thuộc lộ trình
Mục lục đề ⌄
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 . If a value repeats without reaching , the process cycles and the original number is unhappy. A happy prime is both an ordinary prime number and a happy number; is not prime. Each data set has an identifier and a candidate . Determine whether is a happy prime.
Input
One line contains two integers and : the data set identifier and the candidate.
Output
Print one line containing , a space, , a space, and YES if is a happy prime or NO otherwise.
Subtasks
- Subtask 1 (20 points): , .
- Subtask 2 (30 points): , .
- Subtask 3 (50 points): , .
Examples
Input
2 7
Output
2 7 YES
Explanation
The number is prime. Squaring and summing its digits yields , so it is happy. With identifier , print 2 7 YES.
Input
1 1
Output
1 1 NO
Explanation
Although 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 is prime. The successive digit-square sums are . Thus both requirements are satisfied and 3 383 YES is printed.