简单不易懂
2024-05-19 15:23:08
发布于:广东
13阅读
0回复
0点赞
#include <iostream>
#include <cmath>
using namespace std;
bool isPrime(int num) {
if (num <= 1) return false;
for (int k = 2; k <= sqrt(num); k++) {
if (num % k == 0) return false;
}
return true;
}
void ikun() {
int n, m;
cin >> n >> m;
int a[101] = {};
int b[101] = {};
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
for (int i = 1; i <= m; i++) {
cin >> b[i];
}
int sum = 0;
for (int j = 1; j <= m; j++) {
int index = b[j];
if (isPrime(a[index])) {
sum += a[index];
}
}
cout << sum;
return;
}
int main(){
ikun();
return 0;
}
这里空空如也
有帮助,赞一个