每日一九度之 题目1047:素数判定

时间限制:1 秒

内存限制:32 兆

特殊判题:

提交:11748

解决:5317

题目描述:

给定一个数n,要求判断其是否为素数(0,1,负数都是非素数)。

输入:

测试数据有多组,每组输入一个数n。

输出:

对于每组输入,若是素数则输出yes,否则输入no。

样例输入:
13
样例输出:
yes

水题。单纯的判断素数!

但是,注意负数和0以及1的情况。

//Asimple
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <cctype>
#include <cstdlib>
#include <stack>
#include <cmath>
#include <set>
#include <map>
#include <string>
#include <queue>
#include <limits.h>
#define INF 0x7fffffff
using namespace std;
const int maxn = 115;
typedef long long ll;
int num;

bool prime(int n){
    if( n <= 1 ) return false;
    for(int i=2; i*i<=n; i++){
        if( n % i == 0 ){
            return false;
        }
    }
    return true;
}

int main(){
    while( ~scanf("%d",&num) ){
        printf(prime(num)?"yes\n":"no\n");
    }
    return 0;
}

 

转载于:https://www.cnblogs.com/Asimple/p/5900110.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值