社区讨论

40分,醉了

B2137判决素数个数参与者 2已保存回复 2

讨论操作

快速查看讨论及其快照的属性,并进行相关操作。

当前回复
2 条
当前快照
1 份
快照标识符
@lo184p3s
此快照首次捕获于
2023/10/22 16:45
2 年前
此快照最后确认于
2023/11/02 16:35
2 年前
查看原帖
CPP
#include <iostream>
#include <cmath>
#include <stdio.h>
using namespace std;
//素数
bool isPrime(int n){
	int m = sqrt(n);
	if(n == 1) return false;
	for(int i = 2; i <= m; i++){
		if(n % i == 0) return false;
	}
	return true;
}

int main(){
	int x , y , sum = 0;
	if(x > y){
		int g;
		g = x;
		x = y;
		y = g;
	}
	cin >> x >> y;
	for(int i = x; i <= y; i++){
	    if(isPrime(i)) sum++;
	}
	cout << sum;
}

回复

2 条回复,欢迎继续交流。

正在加载回复...