解
2025-08-04 18:35:45
发布于:广东
2阅读
0回复
0点赞
#include<bits/stdc++.h>
bool is_prime(int x) {
if (x <= 1) return false;
if (x == 2) return true;
if (x % 2 == 0) return false;
for (int i = 3; i * i <= x; i += 2) {
if (x % i == 0) return false;
}
return true;
}
int main() {
int n, m;
scanf("%d %d", &n, &m);
int a[1000];
for (int i = 0; i < n; ++i) {
scanf("%d", &a[i]);
}
int total = 0;
for (int i = 0; i < m; ++i) {
int q;
scanf("%d", &q);
int num = a[q - 1];
if (is_prime(num)) {
total += num;
}
}
printf("%d\n", total);
return 0;
}
这里空空如也
有帮助,赞一个