zoukankan      html  css  js  c++  java
  • 每日一九度之 题目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
    ":"no
    ");
        }
        return 0;
    }
    低调做人,高调做事。
  • 相关阅读:
    python3中内置函数map 和 reduce函数的使用
    爬山算法和模拟退火算法
    Link-Cut Tree(LCT)
    启发式搜索——A*算法
    树上分块
    CodeChef TRIPS-Children Trips 树上分块
    CodeChef:Chef and Problems(分块)
    莫队算法
    Konig定理及证明
    块状链表
  • 原文地址:https://www.cnblogs.com/Asimple/p/5900110.html
Copyright © 2011-2022 走看看