题解 | #判断一个数是不是质数#

判断一个数是不是质数

http://www.nowcoder.com/practice/b8bb5e7703da4a83ac7754c0f3d45a82

#include <iostream>
#include <cmath>
using namespace std;

int main() {

    // write your code here......
    long long int n;
    cin>>n;
    if(n<=1){
    	return 0;
	}
    for(int i=2;i<=sqrt(n);i++){
			if(n%i==0){
				cout<<"不是质数"<<endl;
				return 0;
			}
    }
    cout<<"是质数"<<endl;

    return 0;
}
全部评论

相关推荐

牛客ID:561366855:期望薪资多少?难以相信这简历找不到工作。说明二本电子信息专业想对口就业非常难。
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务