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