bài này làm sao sai test 6,7,8,9,11,12,13,14,16,20 trong python 3:
def is_divisible_by_M(number, M):
return number % M == 0
def find_max_divisible(N, M):
digits = sorted(str(N), reverse=True)
for i in range(len(digits)):
if digits[i] != '0':
for j in range(i + 1, len(digits)):
candidate = int(''.join(digits[:i] + [digits[j]] + digits[i+1:j] + [digits[i]] + digits[j+1:]))
if is_divisible_by_M(candidate, M):
return candidate
return 0
N = int(input())
M = int(input())
result = find_max_divisible(N, M)
print(result)
Bình luận
bài này làm sao sai test 6,7,8,9,11,12,13,14,16,20 trong python 3:
def is_divisible_by_M(number, M):
return number % M == 0
def find_max_divisible(N, M):
digits = sorted(str(N), reverse=True)
for i in range(len(digits)):
if digits[i] != '0':
for j in range(i + 1, len(digits)):
candidate = int(''.join(digits[:i] + [digits[j]] + digits[i+1:j] + [digits[i]] + digits[j+1:]))
if is_divisible_by_M(candidate, M):
return candidate
return 0
N = int(input())
M = int(input())
result = find_max_divisible(N, M)
print(result)
nhớ tab vào nha
hay