吾想问
查看原帖
吾想问
1200568
___LuXun___楼主2024/9/22 16:07
#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。

大概是有点不同的罢。不同之处?

2024/9/22 16:07
加载中...