#include <bits/stdc++.h>
using namespace std;
int x, y;
int ans = 0;
bool is_P(int n) {
if (n < 2) {
return false;
}
for (int i = 2; i * i <= n; i++) {
if (n % i == 0) {
return false;
}
}
return true;
}
int main() {
cin >> x >> y;
if (x > y)
swap(x, y);
for (int i = x; i <= y; i++)
if (is_P(i))
ans++;
cout << ans;
return 0;
}
↑这个A了
#include <bits/stdc++.h>
using namespace std;
int x, y;
int ans = 0;
bool is_P(int n) {
if (n < 2) {
return false;
}
for (int i = 2; i * i <= n; i++) {
if (n % i == 0) {
return false;
}
}
return true;
}
int main() {
cin >> x >> y;
if (x < y)
swap(x, y);
for (int i = x; i <= y; i++) {
if (is_P(i))
ans++;
}
cout << ans;
return 0;
}
↑这个20。
大概是有点不同的罢。不同之处?