题解 | #2的幂次方#
2的幂次方
https://www.nowcoder.com/practice/7cf7b0706d7e4b439481f53e5fdac6e7
import math list1 =['2(0)','2','2(2)','2(2+2(0))','2(2(2))','2(2(2)+2(0))','2(2(2)+2)','2(2(2)+2+2(0))','2(2(2+2(0)))','2(2(2+2(0))+2(0))','2(2(2+2(0))+2)','2(2(2+2(0))+2+2(0))','2(2(2+2(0))+2(2))','2(2(2+2(0))+2(2)+2(0))','2(2(2+2(0))+2(2)+2)'] n = eval(input()) list2 = [] ans = '' inx = 0 for i in range (14,-1,-1): if int(math.pow(2,i)) <= n: list2.append(i) n -= int(math.pow(2,i)) for i in range(len(list2)): inx = list2[i] ans += list1[inx] if i != len(list2) - 1: ans += '+' print(ans)