python-3.x 代码部队的可除性问题(1328A),我在visual studio中得到了所需的输出,但在代码部队中测试用例失败了,为什么?

mfuanj7w  于 2022-12-15  发布在  Python
关注(0)|答案(2)|浏览(85)

question - Divisibility Problem (1328A)
这是我的准则

t = int(input())
lst = []
for i in range(0,t):
    nums = list(map(int,input().split()))
    result = (nums[0] % nums[-1])
    lst.append(result)
for i in range(0,len(lst)):
    print(lst[i])

My visual studio code
output in codeforce

exdqitrt

exdqitrt1#

你的逻辑是有缺陷的,你正在寻找迭代的次数,增加b会导致数字之间的可分性,问题是要求你在每一步增加a

wswtfjt7

wswtfjt72#

#1328A
user = int(input())
for i in range(user):
  n = int(input())
  m = int(input())
c = 0
if n%m==0:
  c = 0
else:
  c = 0
  b = True
  while b==True:
    if n>m*2:
      n= n-1
      c+=1
      if n%m == 0:
        b = False
    else:
      n= n+1
      c+=1
      if n%m == 0:
        b = False
print(c)

相关问题