#t129. 幸运数
幸运数
Lucky Number
Problem Description
Xiaoming invented a kind of "lucky number". For a positive integer, its even positions stay unchanged (the units digit is position , the tens digit is position , and so on), while its odd positions are transformed as follows: multiply the digit by ; if the result is not greater than , use it as the transformed result; otherwise add up the digits of the result, and if that sum is not greater than , use it as the transformed result; otherwise (the sum is still greater than ) keep adding the digits until the result is not greater than , and use that as the transformed result. After the transformation, add up the digits of the transformed result; if the sum is a multiple of , the original positive integer is called a lucky number.
For example, for : the st digit is , multiplied by gives , which is greater than ; adding its digits gives , still greater than ; adding again gives as the final result. The rd digit is , transformed to . The th digit is , transformed to . The final transformed result is , whose digit sum is , a multiple of . Therefore is a lucky number.
The corresponding multiple-choice and true/false questions can be found at https://ti.luogu.com.cn/problemset/1126 .
Input Format
The first line contains a positive integer , the number of positive integers to be judged. It is guaranteed that .
The following lines, starting from line , each contain one positive integer to be judged. These positive integers are guaranteed to be less than .
Output Format
Output lines, indicating whether each of the positive integers is a lucky number: if yes output T, otherwise output F.
Hint: you do not need to wait for all input to finish before outputting in order; you may read a number, judge it, output the result, then read the next number.
Sample Input
2
16347
76344
Sample Output
T
F
Sample Explanation
For the first positive integer to be judged, , its odd positions are transformed while even positions stay unchanged, yielding , whose digit sum is , a multiple of , so it is a lucky number and T is output. For the second positive integer to be judged, : the units digit (position ) multiplied by gives , is still greater than , adding again gives , transformed to ; the tens digit stays unchanged; the hundreds digit multiplied by gives , , transformed to ; the thousands digit stays unchanged; the ten-thousands digit multiplied by gives , , , transformed to . Combining them gives , whose digit sum is , not a multiple of , so it is not a lucky number and F is output.
Constraints
- Each positive integer to be judged is