You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

23 lines
503 B

#include<bits/stdc++.h>
using namespace std;
int main() {
//打开文件,改一下文件名
freopen("prime.txt", "w", stdout);
//x和y分别是要打表的素数开始值和结束值
int a, b;
int x, y, num = 0;;
cin >> x >> y;
for (a = x; a <= y; a++) {
for (b = 2; b <= sqrt(a); b++) {
if (a % b == 0) break;
}
if (b > sqrt(a)) {
cout << a << ",";
num++;
}
}
cout << endl << num;
return 0;
}