Square every digit of a positive integer n and add the squares together. Do the same calculation again on the sum you get. If repeating this ever produces 1, then n is a happy number.
700 is a happy number.
2 is not a happy number.
A prime is a number with no divisors other than 1 and itself. 2, 3, 5, 7, 11, 13, 17, 19, ... are primes.
A happy prime is a number that is both prime and happy. 7, 13, 19, ... are happy primes.
Given n, write a program that finds every happy prime less than or equal to n.
The first line contains n (10≤n≤1000000).
Print every happy prime less than or equal to n in increasing order, one per line.