#B3850. Lucky Number
Lucky Number
Lucky Number
A positive integer is defined as a Lucky Number by the following process. Consider the digits of the number from right to left (the units digit is the 1st position, the tens digit is the 2nd position, and so on). For digits in odd positions, perform the following transformation:
- Multiply the digit by 7.
- If the product is greater than 9, repeatedly replace the number by the sum of its digits until the result is not greater than 9. Formally, if a digit in an odd position is d, compute \( x = 7d \), then while \( x > 9 \), update \( x = \sum_{i} x_i \) (where \( x_i \) denotes the digits of \( x \)).
For digits in even positions, keep the digit unchanged. After transforming each digit according to its position, construct a new number using the transformed digits (maintaining the original positions). Finally, sum all the digits of this new number. If the total sum is a multiple of 8, then the original number is a Lucky Number.
Example: Consider the number \(16347\). Its digits (from right to left) are: 7 (1st), 4 (2nd), 3 (3rd), 6 (4th), and 1 (5th). For odd positions:
- 1st digit: \(7 \times 7 = 49\) \(\to 4+9=13 \to 1+3=4\).
- 3rd digit: \(3 \times 7 = 21\) \(\to 2+1=3\).
- 5th digit: \(1 \times 7 = 7\) (no further transformation needed as 7 \(\le 9\)).
For even positions, the digits remain the same. Thus, the transformed number is formed (from left to right) as \(7, 6, 3, 4, 4\) whose digit sum is \(7+6+3+4+4=24\), a multiple of 8. Therefore, \(16347\) is a Lucky Number.
inputFormat
The input consists of a single line containing a positive integer.
For example:
16347
outputFormat
Output a single line with YES
if the number is a Lucky Number, and NO
otherwise.
sample
16347
YES