-->
当前位置:首页 > 题库

PROGRAMMING:Independent happiness

Luz5年前 (2021-05-10)题库437
To sum the squares of the digits of a decimal number is called an iteration. If a decimal number can get 1 through several iterations, it is called happy number. One is a happy number. In addition, for example, 19 gets 82 after one iteration, 68 after two iterations, 100 after three iterations, and finally 1. Then 19 is the number of happiness. Obviously, in the process of iterating a happiness number to 1, all the numbers are happiness numbers, and their happiness is dependent on the initial number. For example, the happiness of 82, 68 and 100 is dependent on 19. The happiness number of a maverick is not attached to any other number in a limited range; Its independence is the number of happiness attached to it. If the number is a prime, its independence is doubled. For example, 19 is an independent happiness number in the interval [1, 100], and its independence is $$2 / times 4 = 8 $$.
On the other hand, if a number greater than 1 enters a dead cycle after several iterations, it is not happy. For example, iteration 29 gets 85, 89, 145, 42, 20, 4, 16, 37, 58, 89,... It can be seen that 89 to 58 forms a dead cycle, so 29 is not happy.
This problem requires you to write a program to list all the independent happiness numbers in a given interval and its independence.
###Input format:
Enter the two endpoints of the closed interval in the first line: $$1 < a < B < Le 10 ^ 4 $$.
###Output format:
According to the increasing sequence, we can get all the independent happiness numbers and their independence in the given closed interval $$[a, b] $. Each pair of numbers occupies one line, and the numbers are separated by a space.
If there is no happiness number in the interval, output 'sad' in one line.
###Input sample 1:
```in
10 40
```
###Output sample 1:
```out
19 8
23 6
28 3
31 4
32 3
```
**Note: in the * * example, 10 and 13 are also happiness numbers, but they are attached to other numbers (such as 23, 31, etc.), so they are not output. Although other numbers are actually attached to other happiness numbers, they are independent happiness numbers in the given interval because they are not in the given interval [10,40].
###Input example 2:
```in
110 120
```
###Output example 2:
```out
SAD
```







answer:If there is no answer, please comment