How many prime numbers

Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)

Total Submission(s): 14686    Accepted Submission(s): 5093

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-bit signed integer, and each of them won’t be less than 2.
 
Output
  For each case, print the number of prime numbers you have found out.
 
Sample Input
3
2 3 4
 
Sample Output
2
 
Author
wangye
 
Source
HDU 2007-11 Programming Contest_WarmUp

#include<cstdio>
#include<cmath>
#include<string.h>
#include<algorithm>
using namespace std;
long long s,ans;
int main()
{
int n;
while(scanf("%d",&n)!=EOF)
{
ans=0;
int flog=1,i;
for(int j=0;j<n;j++)
{
scanf("%lld",&s);
for(i=2,flog=1;flog&&i<=sqrt(s);i++)
if(s%i==0)
flog=0;
if(flog)
ans++;
}
printf("%d\n",ans);
}
return 0;
}

 

hdoj--2138--How many prime numbers(暴力模拟)的更多相关文章

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

    Problem Description Give you a lot of positive integers, just to find out how many prime numbers the ...

  2. HDU 2138 How many prime numbers(Miller_Rabin法判断素数 【*模板】 用到了快速幂算法 )

    How many prime numbers Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/O ...

  3. 【HDU】2138 How many prime numbers

    http://acm.hdu.edu.cn/showproblem.php?pid=2138 题意:给n个数判断有几个素数.(每个数<=2^32) #include <cstdio> ...

  4. HDU 2138 How many prime numbers

    米勒罗宾素数测试: /* if n < 1,373,653, it is enough to test a = 2 and 3. if n < 9,080,191, it is enoug ...

  5. HDU 2138 How many prime numbers (判素数,米勒拉宾算法)

    题意:给定一个数,判断是不是素数. 析:由于数太多,并且太大了,所以以前的方法都不适合,要用米勒拉宾算法. 代码如下: #include <iostream> #include <c ...

  6. POJ 2739 Sum of Consecutive Prime Numbers( *【素数存表】+暴力枚举 )

    Sum of Consecutive Prime Numbers Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 19895 ...

  7. Alexandra and Prime Numbers(思维)

    Alexandra and Prime Numbers Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (J ...

  8. How many prime numbers(求素数个数)

    How many prime numbers Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/O ...

  9. UESTC 1272 Final Pan's prime numbers(乱搞)

    题目链接 Description Final Pan likes prime numbers very much. One day, he want to find the super prime n ...

随机推荐

  1. Spring注解+Axis2开发WebService

    用Spring注解方式: 配置扫描指定包下的类 <context:component-scan base-package="包名" />   标识类为spring管理的 ...

  2. 洛谷——T P2136 拉近距离

    https://www.luogu.org/problem/show?pid=2136 题目背景 我是源点,你是终点.我们之间有负权环. ——小明 题目描述 在小明和小红的生活中,有N个关键的节点.有 ...

  3. HDU 1211

    水.模拟即可.使用EXGCD求逆元 #include <iostream> #include <cstdio> #include <cstring> #includ ...

  4. HDU 2879

    利用x<n的信息,可以证得当n为素数时,he[n]=2;同时,若n 为素数,则有HE[N^K]=2;因为若等式成立则有n|x(x-1).抓住这个证即可. 至于符合积性函数,想了很久也没想出来,看 ...

  5. IntelliJ IDEA could not autowire no beans of 'Decoder'

    IntelliJ IDEA could not autowire no beans of  'Decoder' 学习了:http://blog.csdn.net/u012453843/article/ ...

  6. 【Allwinner ClassA20类库分析】 2.free pascal语法及结构简析

        上一节介绍了Lazarus一般的开发操作流程,对于不熟悉pascal语言的朋友可能看的还是不大明确.不知道pascal代码里都应该包括什么或起什么作用.这回就简单地介绍下语法及代码文件的结构. ...

  7. Android socket 使用PrintWriter和BufferedReader发送和接收出现乱码问题解决

    项目中用到了Android和C++的通信.选择了用socket 发送字符的方式,一開始使用的代码是: socket=new Socket(); InetSocketAddress isa = new ...

  8. 开心的小明(南阳oj49)(01背包)

    开心的小明 时间限制:1000 ms  |  内存限制:65535 KB 难度:4 描写叙述 小明今天非常开心.家里购置的新房就要领钥匙了,新房里有一间他自己专用的非常宽敞的房间.更让他高兴的是,妈妈 ...

  9. FPGA视频拼接器的放大和缩小功能

    视频视频器能够把信号源放大和缩小. 对于我们的拼接器而言,它的架构这种: 信号源进入到拼接器中.先进入缩小模块.然后存进DDR中.然后从DDR中读出视频.进入到放大模块,最后依据屏幕的位置,输出到屏幕 ...

  10. virtio netdev的创建

    Linux眼下支持至少了8种虚拟化系统: Xen KVM VMware's VMI IBM's System p IBM's System z User Mode Linux lguest IBM's ...