How many prime numbers(素数)
2 3 4
#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(素数)的更多相关文章
- POJ 2739 Sum of Consecutive Prime Numbers(素数)
POJ 2739 Sum of Consecutive Prime Numbers(素数) http://poj.org/problem? id=2739 题意: 给你一个10000以内的自然数X.然 ...
- 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 ...
- CodeForces 385C Bear and Prime Numbers 素数打表
第一眼看这道题目的时候觉得可能会很难也看不太懂,但是看了给出的Hint之后思路就十分清晰了 Consider the first sample. Overall, the first sample h ...
- UVA 10539 - Almost Prime Numbers 素数打表
Almost prime numbers are the non-prime numbers which are divisible by only a single prime number.In ...
- poj 2739 Sum of Consecutive Prime Numbers 素数 读题 难度:0
Sum of Consecutive Prime Numbers Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 19697 ...
- Codeforces 385C Bear and Prime Numbers(素数预处理)
Codeforces 385C Bear and Prime Numbers 其实不是多值得记录的一道题,通过快速打素数表,再做前缀和的预处理,使查询的复杂度变为O(1). 但是,我在统计数组中元素出 ...
- 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 ...
- Codeforces 385C - Bear and Prime Numbers(素数筛+前缀和+hashing)
385C - Bear and Prime Numbers 思路:记录数组中1-1e7中每个数出现的次数,然后用素数筛看哪些能被素数整除,并加到记录该素数的数组中,然后1-1e7求一遍前缀和. 代码: ...
- Sum of Consecutive Prime Numbers(素数打表+尺取)
Description Some positive integers can be represented by a sum of one or more consecutive prime numb ...
- 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 ...
随机推荐
- js阻止冒泡
js阻止冒泡 (ev || event).cancelBubble = true; 标签切换 <script type="text/javascript"> windo ...
- 改动symbol link的owner
当/home/jenkins文件夹空间不足的时候,能够先查看哪个文件夹在较大的磁盘分区上,然后将jenkins文件夹移动过去 最后创建/home/jenkins link到新位置. 这时候须要改动sy ...
- UVa 524 Prime Ring Problem(DFS , 回溯)
题意 把1到n这n个数以1为首位围成一圈 输出全部满足随意相邻两数之和均为素数的全部排列 直接枚举排列看是否符合肯定会超时的 n最大为16 利用回溯法 边生成边推断 就要快非常多了 #inc ...
- uboot的relocation原理具体分析
近期在一直在做uboot的移植工作,uboot中有非常多值得学习的东西.之前总结过uboot的启动流程,但uboot一个非常核心的功能没有细致研究.就是uboot的relocation功能. 这几天研 ...
- 深入浅出JMS(一)——JMS简要
假设手机只能实时通话.没有邮件和短信功能发生?一个电话回来.只是没有足够的时间去连接.然后传递这款手机的信息肯定是不接受. 么不能先将信息存下来.当用户须要查看信息的时候再去获得信息呢?伴随着这个疑惑 ...
- IBatis增删改差的实现以及注意点
此次进讲述对表操作的实现细节.废话不多说,代码见真章. <?xml version="1.0" encoding="utf-8" ?> <sq ...
- Notification和Activity交互
概述 通知(Notification)就是程序在不影响用户操作的情况下,通过手机顶部弹出消息告诉用户的一种信息通知方式,而且能够通过下拉通知操作抽屉通知,实现Notification与活动.通知和服务 ...
- linux学习(一个) 在unbuntu通过添加新的用户
最近安装了双系统,开始折腾unbuntu该.Linux系统是一个多用户操作系统,非常多的人才完整的操作需要管理员权限,完全管理员权限是非常重要的.人谁是刚开始学习,般用户的权限即可了,相对于刚開始学习 ...
- 简单vector达到
得知c++于,看完这本书后,,最近苦于不知道下一步该怎么做了,在寻找STL在各种容器的源代码分析,我想一次又一次地实现它. 之前,很多问题看的时候不知道是怎么回事,意与理解的.这个vector类写得特 ...
- 终端查询数据库sqlite(创建你自己,或者是coredata创建)那里的东西
首先需要知道数据库的路径,coredata一般都是在沙箱中创建Documents目录的.虽然他建立了自己看, sqlite3 #数据库路径# //进入数据库 .tables //查看数 ...