Python题解
2024-12-07 15:21:11
发布于:浙江
1阅读
0回复
0点赞
n, m = map(int, input().split())
cards = list(map(int, input().split()))
indices = list(map(int, input().split()))
def is_prime(y):
if y < 2:
return False
for i in range(2, int(y**0.5) + 1):
if y % i == 0:
return False
return True
selected_cards = [cards[i-1] for i in indices]
prime_sum = sum(card for card in selected_cards if is_prime(card))
print(prime_sum)
这里空空如也
有帮助,赞一个