Preparing NOJ

# Happy Prime Number

1000ms 65536K

## Description:

A Happy Number can be defined as follows. From a positive integer n, calculate the sum of square of each digit of n. Then from that sum, repeat the same process over and over again. This cycle terminates if and only if there is 1 in the sequence. Hence, we call the number n a happy number if it generates a finite sequence. Otherwise, the endless cycle occurs (1 never appears in the sequence). We

may call the number generating an endless cycle an unhappy number . Observe the following examples:

700 is a happy number72+02 +02 =49 12 +32 +02 =10

2 is not a happy number
22=4
3
2 +72 =58
1
2 +42 +52=42
4
2 = 16 ... and never terminates

42 +92 =97 12 +02 =1

92 +72 =130

12+62=37 82 +92 =14 22 +02 =4

42 =16
5
2 +82 =89 42 +22 =20

A Prime Number is an integer greater than 1 that can be divided only by 1 and itself. Here are some prime numbers: 2, 3, 5, 7, 11, 13, 17, 19, ...

A Happy Prime Number is a prime number which also satisfies the happy number condition such as 7, 13, 19, ...

Your task is to write a program to show all happy prime numbers less than or equal to a given numbern. (10 n 1000000)

## Input:

A positive number n is the only input of the program

## Output:

the program prints all happy numbers in ascending order, one number in a line.

## Sample Input:

20

## Sample Output:

71319

## Note:

Info

Provider NOJ

Code NOJ1458

Tags

Submitted 1

Passed 1

AC Rate 100%

Date 04/20/2019 10:03:10

Related

Nothing Yet