The title
Given two positive integers N 1 <N 2. Multiply the cubicles of each digit from N 1 to N 2, and sum the resulting digits to get a new batch of digits. Repeat the process for the new batch of digits until all digits are 1-digits. The “king of numbers” is the one with the most numbers.
For example, if N 1 =1 and N 2 =10, {1, 8, 9, 10, 8, 9, 10, 8, 18, 0} is obtained after the first round of operation; After the second round of operation, {1, 8, 18, 0, 8, 18, 0, 8, 8, 0}; After the third operation, {1, 8, 8, 0, 8, 8, 0, 8, 8, 8, 0, 8, 8, 0} is obtained. So the king of numbers is 8.
Find the king of numbers for any given N 1 <N 2.
Input format: Enter two positive integers 0<N 1 <N 2 ≤10 3 in the first line, separated by Spaces.
Output format: The number of occurrences of the king of numbers is first printed in one line, followed by the king of numbers in the second line. For example, for input 1, 10 should print 6 and 8 in two lines. If there are parallel Kings of numbers, output in ascending order. Digits are separated by one space. There must be no extra space at the beginning and end of each line.
Input example: 10 14 No blank line at the end Output example: 2 0 8 No blank line at the endCopy the code
Their thinking
start,end = map(int,input().split()) # start,end = map(int,"10 14".split()) # start,end = map(int,"1 10".split()) inputList = [str(i) for i in range(start, end+1)] def actionRes(a:str) -> str: res = 1 for i in a: res = res *(int(i)**3) b = str(res) resb = 0 for j in b: resb += int(j) return str(resb) def sumLength(list:[str])->int: res = 0 for i in list: res += len(i) return res while sumLength(inputList) ! = len(inputList): for index,val in enumerate(inputList): inputList[index] = actionRes(val) # print(inputList) from collections import Counter res = Counter(inputList).most_common() if len(res) == 0: print("") else: resOutput = [int(x) for x,y in res if y == res[0][1]] resOutput.sort() print(res[0][1]) resOutput = [str(x) for x in resOutput] print(" ".join(resOutput))Copy the code