题目是:
怎么ac,我的代码是:
from math import gcd
def count_red_to_blue(n, m, ops):
res = []
visited = [False] * (n + 1)
for op in ops:
cnt = 0
for i in range(0, n, gcd(n, op)):
if not visited[i]:
cnt += 1
visited[i] = True
res.append(cnt)
return res
# 读取输入数据
n, m = map(int, input().strip().split())
ops = list(map(int, input().strip().split()))
# 计算每轮操作中红色珍珠变为蓝色的数量
result = count_red_to_blue(n, m, ops)
# 输出结果
print(*result)
import math
n, m = map(int, input().split())
a = list(map(int, input().split()))
necklace = ['r'] * n
def handle_ray(a_i):
count = 0
for i in range(0, math.lcm(a_i, n)+1, a_i):
i %= n
if necklace[i] == 'r':
necklace[i] = 'b'
count += 1
elif necklace[i] == 'b':
necklace[i] = 'b'
return count
for ai in a:
count = handle_ray(ai)
print(count, end=' ')