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
 #include<stdio.h>
#include<math.h>
int prime(int x)
{ int i;
if(x<=) return ;
for(i=;i<=sqrt(x*1.0);i++) //i*i<=x 是会超时的,因为i*i每次都要计算
{
if(x%i==)
{
return ;
break;
}
}
return ;
}
int main()
{
int n;
int i;
int sum;
int a;
while(scanf("%d",&n)!=EOF)
{
sum=;
for(i=;i<n;i++)
{
scanf("%d",&a);
if(prime(a))
sum++;
}
printf("%d\n",sum);
}
return ; }

How many prime numbers(素数)的更多相关文章

  1. POJ 2739 Sum of Consecutive Prime Numbers(素数)

    POJ 2739 Sum of Consecutive Prime Numbers(素数) http://poj.org/problem? id=2739 题意: 给你一个10000以内的自然数X.然 ...

  2. 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 ...

  3. CodeForces 385C Bear and Prime Numbers 素数打表

    第一眼看这道题目的时候觉得可能会很难也看不太懂,但是看了给出的Hint之后思路就十分清晰了 Consider the first sample. Overall, the first sample h ...

  4. UVA 10539 - Almost Prime Numbers 素数打表

    Almost prime numbers are the non-prime numbers which are divisible by only a single prime number.In ...

  5. poj 2739 Sum of Consecutive Prime Numbers 素数 读题 难度:0

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

  6. Codeforces 385C Bear and Prime Numbers(素数预处理)

    Codeforces 385C Bear and Prime Numbers 其实不是多值得记录的一道题,通过快速打素数表,再做前缀和的预处理,使查询的复杂度变为O(1). 但是,我在统计数组中元素出 ...

  7. algorithm@ Sieve of Eratosthenes (素数筛选算法) & Related Problem (Return two prime numbers )

    Sieve of Eratosthenes (素数筛选算法) Given a number n, print all primes smaller than or equal to n. It is ...

  8. Codeforces 385C - Bear and Prime Numbers(素数筛+前缀和+hashing)

    385C - Bear and Prime Numbers 思路:记录数组中1-1e7中每个数出现的次数,然后用素数筛看哪些能被素数整除,并加到记录该素数的数组中,然后1-1e7求一遍前缀和. 代码: ...

  9. Sum of Consecutive Prime Numbers(素数打表+尺取)

    Description Some positive integers can be represented by a sum of one or more consecutive prime numb ...

  10. 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 ...

随机推荐

  1. Xamarin.Android 在VS下调试时提示 In mgmain JNI_OnLoad 程序“Mono”已退出 解决办法

    原因是使用了破解版的 Xamarin,调试时不能使用共享库

  2. 每天进步一点点之SQL 获取表中某个时间字段离当前时间最近的几条

    实际中用到的SQL: select * from (select top 3 Id, case when startSignup>GETDATE() then '敬请期待' when (star ...

  3. 升级iOS8系统后,保险箱Pro、私人保险箱、私密相冊打开就闪退的官方解决方式

    升级iOS8系统后,保险箱Pro.私人保险箱.私密相冊打开就闪退的官方解决方式   写在前面的话: 1.   本文适用条件    适用于:您的保险箱Pro.私人保险箱.私密相冊在iPhone或iPad ...

  4. JList用法小结

    JList用法小结 分类: JAVA技术2007-08-11 01:02 18485人阅读 评论(11) 收藏 举报 stringvectorclassjavaactionobject         ...

  5. js防堵塞载入

    js防堵塞载入 <script type="text/javascript"> function scriptDomElement (u) { var s = docu ...

  6. iOS_18_开关控制器_NavigationController_push道路_数据传输

    最后效果图: watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvcHJlX2VtaW5lbnQ=/font/5a6L5L2T/fontsize/400/fill ...

  7. js运动动画

    原文:js运动动画 今天简单的学了一下js运动动画,再此感谢慕课网的这位老师http://www.imooc.com/view/167,讲的很不错. 下面是我整理出来的结果. 知识点一:速度动画. 1 ...

  8. 《Pro Android Graphics》读第三季度票据

    Android Frame Animation: XML, Concepts and Optimization Frame Animation Concepts: Cels, Framerate, a ...

  9. 电脑知识--Windows一片

    .com档 Dos可执行命令文件,一般小于64kb, .com文件包括程序的一个绝对映像.就是说,为了执行程序准确的处理器指令和内存中的数据.Ms-Dos通过直接把该映像从文件复制到内存. 而 载入. ...

  10. IOC/DI的基本思想

    IOC/DI的基本思想 1.把程序之间的依赖关系去掉 2.把程序对象设置到IOC/DI容器的配置中作为Bean 3.由IOC/D.容器来管理Bean的创建和实例化 4.由IOC/DI容器来把Bean之 ...