hdu 2138 How many prime numbers

http://acm.hdu.edu.cn/showproblem.php?pid=2138

#include <iostream>
#include <cstdio>
#include <cmath>
using namespace std;
bool isprime(int m)
{
    if(m == 1)
        return 0;
    int n=sqrt((double)m);
    for(int i=2; i<=n; i++)
      if(m%i == 0)
        return 1;
    return 0;
}
int main()
{
    int m,n;
    while(~scanf("%d",&m))
    {
        int sum=0;
        while(m--)
        {
            scanf("%d",&n);
            if(!isprime(n))
                sum++;
        }
        printf("%d\n",sum);
    }
    return 0;
}
时间: 2025-01-20 19:00:17

hdu 2138 How many prime numbers的相关文章

HDOJ(HDU) 2138 How many prime numbers(素数-快速筛选没用上、)

Problem Description Give you a lot of positive integers, just to find out how many prime numbers there are. Input There are a lot of cases. In each case, there is an integer N representing the number of integers to find. Each integer won't exceed 32-

poj 2739 Sum of Consecutive Prime Numbers【素数筛】

我觉得这题的数据应该有些刁钻,一共至少提交了五次,一直是WA,无语了......用一个result数组存素数硬是不对.后来就算了,改用直接判断(法二),继续WA,后来发现是MAXN至少应为10002(被数据坑了),终于A掉了...... 后来继续改法一多次,任然WA,一直不清楚原因. 继续思考发现有一个很隐蔽的问题就是我后来用到   if(result[i]>n) break;    而result数组中 10000以内 最后一个素数是 9997,后面全是0了.这样无法停止,所以必须加一个大数作

UVa 10392 Factoring Large Numbers:素因子分解

10392 - Factoring Large Numbers Time limit: 3.000 seconds http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=100&page=show_problem&problem=1333 One of the central ideas behind much cryptography is that factoring

UVa 10924 Prime Words:素数

10924 - Prime Words Time limit: 3.000 seconds http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem&problem=1865 A prime number is a number that has only two divisors: itself and the number one.

poj 3126 Prime Path

Prime Path Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 14374   Accepted: 8112 Description The ministers of the cabinet were quite upset by the message from the Chief of Security stating that they would all have to change the four-dig

10 001st prime number

这真是一个耗CPU的运算,怪不得现在因式分解和素数查找现在都用于加密运算. By listing the first six prime numbers: 2, 3, 5, 7, 11, and 13, we can see that the 6th prime is 13. What is the 10 001st prime number? def isprime(n): boolisprime = True for i in xrange(2,n): if n % i == 0: bool

八、设置HTTP应答头

 8.1 HTTP应答头概述 Web服务器的HTTP应答一般由以下几项构成:一个状态行,一个或多个应答头,一个空行,内容文档.设置HTTP应答头往往和设置状态行中的状态代码结合起来.例如,有好几个表示"文档位置已经改变"的状态代码都伴随着一个Location头,而401(Unauthorized)状态代码则必须伴随一个WWW-Authenticate头. 然而,即使在没有设置特殊含义的状态代码时,指定应答头也是很有用的.应答头可以用来完成:设置Cookie,指定修改日期,指示浏览器按照

jsp Servlet基础入门学习:设置HTTP应答头

js|servlet     8.1 HTTP应答头概述 Web服务器的HTTP应答一般由以下几项构成:一个状态行,一个或多个应答头,一个空行,内容文档.设置HTTP应答头往往和设置状态行中的状态代码结合起来.例如,有好几个表示"文档位置已经改变"的状态代码都伴随着一个Location头,而401(Unauthorized)状态代码则必须伴随一个WWW-Authenticate头. 然而,即使在没有设置特殊含义的状态代码时,指定应答头也是很有用的.应答头可以用来完成:设置Cookie,

JSP中设置HTTP应答头

js PrimeNumbers.java 注意,该Servlet要用到前面给出的ServletUtilities.java.另外还要用到:PrimeList.java,用于在后台线程中创建一个素数的Vector:Primes.java,用于随机生成BigInteger类型的大数字,检查它们是否是素数.(此处略去PrimeList.java和Primes.java的代码.) package hall; import java.io.*;import javax.servlet.*;import j