ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#213367 | #2355. Digit | wangyaxu123 | 0 | 0ms | 0kb | Python3 | 703b | 2024-11-11 20:25:34 | 2024-11-11 23:03:59 |
answer
def a(n):
queue = [(0, 0)] # 用队列存储 (当前值, 加1操作次数) 的元组,初始为 (0, 0)
visited = set() # 用于记录已经访问过的数值,避免重复计算
while queue:
current_value, add_ones_count = queue.pop(0)
if current_value % n == 0 and current_value > 0:
return add_ones_count
if current_value not in visited:
visited.add(current_value)
# 进行乘以10的操作
queue.append((current_value * 10, add_ones_count))
# 进行加1的操作
queue.append((current_value + 1, add_ones_count + 1))
result = a(216)
print("a(3)的值为:", result)
详细
小提示:点击横条可展开更详细的信息
Test #1:
score: 0
Dangerous Syscalls
input:
81920
output:
result:
Test #2:
score: 0
Dangerous Syscalls
input:
55966
output:
result:
Test #3:
score: 0
Dangerous Syscalls
input:
92661
output:
result:
Test #4:
score: 0
Dangerous Syscalls
input:
68013
output:
result:
Test #5:
score: 0
Dangerous Syscalls
input:
72927
output:
result:
Test #6:
score: 0
Dangerous Syscalls
input:
15047
output:
result:
Test #7:
score: 0
Dangerous Syscalls
input:
59994
output:
result:
Test #8:
score: 0
Dangerous Syscalls
input:
97273
output:
result:
Test #9:
score: 0
Dangerous Syscalls
input:
51139
output:
result:
Test #10:
score: 0
Dangerous Syscalls
input:
55788