最近提交代码时常会出现RE,我下载了测试代码对比了一下发现跟答案没有差别,没区别为啥判我错啊..
题目原题在这 https://www.luogu.com.cn/problem/P7071
这是我的代码
def binary_search(n):
l = 0
r = 25
while l <= r:
mid = l + (r-l) // 2
k = 2 ** mid
if k > n:
r = mid - 1
elif k == n:
nums.append(k)
return True
else:
if k * 2 == n:
nums.append(k * 2)
return True
elif k * 2 > n:
nums.append(k)
return False
l = mid + 1
nums = []
n = int(input())
if n % 2 != 0:
print(-1)
else:
while not binary_search(n):
n -= nums[-1]
#print(nums)
for i in nums:
print(i,end=" ")