猫史档案馆


【C++/NOIP真题】

用户:芥末不是酱油芥末不是酱油查看:0 回复:2 评论:0 创建时间:2023-01-18T12:56:25


NOIP有很多题的一部分判断都有这东西,有两种方法:

#include <iostream>
#include <cmath>
using namespace std;
int qqq(int h){
	int q = 2;
	if (h==2){
		return 1;
	}
	while (q<=sqrt(h) && h%q!=0){
		q++;
		if (h%q==0){
			return 0;
		}
		else{
			return 1;
		}
	}
}
int main(){
	int a;
	cin >> a;
	if (qqq(a)==1){
            cout << "True";
    }
    else{
            cout << "False";
    }
	return 0;
}
#include <iostream>
#include <cmath>
using namespace std;
bool qqqq(int h){
	int i=2;
	for (i=2;(i<=sqrt(h) && h%i!=0);++i);
	if (i==sqrt(h)+1) return 1;
	else return 0;
}
int main(){
	int a;
	cin >> a;
	if (qqqq(a)==1){
            cout << "True";
    }
    else{
            cout << "False";
    }
	return 0;
}


回复

上一页1 页 / 共 1下一页
芥末不是酱油芥末不是酱油

判断素数(质数)

点赞0


评论


芥末不是酱油芥末不是酱油

1F.1D.1A.1E.28.1A.1F.1F.1A.1F.1X.1A.1E.2F.1A.1E.28.1A.1F.1E.1A.1F.1X.1A.1E.2F.1A.1E.2C.1A.1F.1K.1A.1E.28.1A.1F.1D.1A.1E.28.1A.1F.1J.1A.1E.2F.1A.1E.28.1A.1E.2D.1A.1E.2C.1A.1F.1E.1A.1E.2E.1A.1F.1H.1A.1E.2G.1A.1D.1K.1A.1E.2D.1A.1E.28.1A.1F.1F.1A.1F.1K.1A.1E.2G.1A.1E.2C.1A.1E.2B.1A.1F.1F.1A.1F.1L.1A.1E.2F.1A.1F.1L.1A.1E.2G.1A.1F.1C.1A.1E.2G.1A.1E.28.1A.1F.1E.1A.1E.2E.1A.1D.1K.1A.1E.2E.1A.1F.1L.1A.1E.28.1A.1F.1E.1A.1F.1J.1A.1E.2F.1A.1F.1L.1A.1E.2G.1A.1E.2A.1A.1E.2F.1A.1E.2G.1A.1F.1K.1A.1E.28.1A.1F.1E.1A.1E.2E.1A.1E.2B.1A.1E.28.1A.1F.1F.1A.1F.1J.1A.1E.2F.1A.1E.2G.1A.1F.1K.1A.1E.2G.1A.1E.28.1A.1F.1E.1A.1F.1K.1A.1E.2G.1A.1E.28.1A.1F.1E.1A.1F.1W.1A.1F.1F.1A.1F.1L.1A.1F.1I.1A.1E.2C.1A.1F.1E.1A.1D.1K.1A.1F.1D.1A.1E.28.1A.1F.1F.1A.1F.1X.1A.1E.2F.1A.1E.28.1A.1F.1E.1A.1F.1E.1A.1E.2G.1A.1E.2B.1A.1E.28.1A.1F.1W.1A.1E.2C.1A.1E.2B.1A.1E.2C

点赞1


评论