How many prime numbers(求素数个数)
How many prime numbers
Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 14684 Accepted Submission(s): 5091
2 3 4
题解:
水暴力,打表不行,由于数据量太大,运行到sqrt(x)就可以;
代码:
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
bool js(int x){
if(x==)return true;
if(x==||x==)return false;
if(x%==)return false;
for(int i=;i<=sqrt(x);i+=){
if(x%i==)return false;
}
return true;
}
int main(){
int N,a;
while(~scanf("%d",&N)){
int cnt=;
for(int i=;i<N;i++){
scanf("%d",&a);
if(js(a))cnt++;
}
printf("%d\n",cnt);
}
return ;
}
How many prime numbers(求素数个数)的更多相关文章
- 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 ...
- POJ 2739 Sum of Consecutive Prime Numbers( *【素数存表】+暴力枚举 )
Sum of Consecutive Prime Numbers Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 19895 ...
- POJ 2739 Sum of Consecutive Prime Numbers【素数打表】
解题思路:给定一个数,判定它由几个连续的素数构成,输出这样的种数 用的筛法素数打表 Sum of Consecutive Prime Numbers Time Limit: 1000MS Memo ...
- 【Aizu - ALDS1_1_C】Prime Numbers(素数筛法)
Prime Numbers Descriptions: A prime number is a natural number which has exactly two distinct natur ...
- LeetCode Count Primes 求素数个数(埃拉托色尼筛选法)
题意:给一个数n,返回小于n的素数个数. 思路:设数字 k =from 2 to sqrt(n),那么对于每个k,从k2开始,在[2,n)范围内只要是k的倍数的都删掉(也就是说[k,k2)是不用理的, ...
- How many prime numbers(素数)
Problem Description Give you a lot of positive integers, just to find out how many prime numbers t ...
- leetcode 204题求素数个数
Description: Count the number of prime numbers less than a non-negative number, n 提示晒数法: http:// ...
- UVA1210Sum of Consecutive Prime Numbers(素数打表 + 连续和)
题目链接 题意:输入一个数n (2 <= n <= 10000) 有多少种方案可以把n写成若干个连续素数之和 打出10000之内的素数表,然后再打出每个可能得到的和的方案数的表 #incl ...
随机推荐
- Oracle 查询时间在当天的数据
要实现这个功能需要用到trunc这个函数对时间的操作 select trunc(sysdate) from dual --2014-12-27 今天的日期为2014-12-27 select trun ...
- 根据不同需求跳转不同Activity的另外一种写法
代码如下: /* Android Asynchronous Http Client Sample Copyright (c) 2014 Marek Sebera <marek.sebera@gm ...
- JQ插件开发方法
由于项目原因,不得不写个JQ侧滑插件来满足需求.. 先引用两篇博文,待测试了 再写怎么做.. http://blog.csdn.net/business122/article/details/8278 ...
- php以fastCGI的方式运行在iis下,遇到的文件系统权限问题及解决方法
今天准备将一个php demo放在IIS下运行,网站在IIS下的配置是这样的: 应用程序池是集成模式下的.net framework 2.0(2.0或4.0没什么关系,因为php以fastCGI的方式 ...
- Archlinux在Btrfs分区上的安装(bios篇)
其实本文所有的内容在Archwiki上都可以找到,并且更新更全面(只是比较零散),我所做的只是对安装流程做一个小小的总结,每一步我都会稍微解释一下,但不会说的特别详细,毕竟这只是一篇安装引导文,而不是 ...
- Use eplipse to develop Python project
Source: This is the example how to use eclipse and python. http://www.360doc.com/content/15/0206/10/ ...
- ffmpeg用法
1. help ffmpeg.exe -h > help.txt 2. 解码: ffmpeg -i 123.264 123.yuv ffmpeg -i 123.264 -vframes 200 ...
- Mybatis入门 digest
http://www.mybatis.org/mybatis-3/zh/configuration.html userDao-mapping.xml相当于是UserDao的实现, 同时也将User实体 ...
- flume 日志采集工具
Flume是Cloudera提供的一个高可用的,高可靠的,分布式的海量日志采集.聚合和传输的系统,Flume支持在日志系统中定制各类数据发送方,用于收集数据:同时,Flume提供对数据进行简单处理,并 ...
- openStack icehouse for centos6.4 production Env 实战
production Env brief Overview: Management Node: controller.cc 10.114.100.115 Neutron Network Node: ...