题解 | #序列找数# 这道题我的思路是分奇偶两种情况
扭蛋机
http://www.nowcoder.com/practice/9d26441a396242a9a0f7d2106fc130c7
这道题我的思路是分奇偶两种情况,如果是奇数,倒推法,最后一次则是2:2x+1,得到x继续倒推,最后如果x==1,则为2:2x+1,如果x==2,则为3:2x+2;偶数亦同。 def ndj(n): list_0 = [] list_final = [] while n > 2: if (n % 2) == 0: n = (n - 2) / 2 list_0.append('3') elif (n % 2) == 1: n = (n - 1) / 2 list_0.append('2') else: if n == 1: list_0.append('2') elif n == 2: list_0.append('3') # print(list_0) for key in list_0[::-1]: list_final.append(key) print(*list_final,sep='') # for num in list_final[::1]: # print(num)
n = int(input()) ndj(n)