#include<iostream>
using namespace std;
int main() {
int x , sum = 0;
for (x = 3; x <= 100;++x) { //从3开始,最后输出时加个1
int y;
for (y = 2; y <= x;) {
if (x == y) {//x==y说明为素数,执行sum+=x
sum += x;
cout << "质数:" << x << endl;
}
else if(x%y==0){//x能整除y说明不是素数,结束此循环
break;
}
else {//一直循环至y==x或者x%y==0
++y;
}
}
}
int z = sum + 1;
cout << z;
system("pause");
return 0;
}
#include<iostream>
using namespace std;
int main() {
int x , sum = 0;
for (x = 2; x <= 100;++x) {
int y;
for (y = 2; y <= x; ++y) {
if (y == x) {
cout << "质数:" << x << "\t";
sum += x;
}
else if (x % y == 0) {
break;
}
}
}