给定整数a和b,请问区间[a,b)内有多少个素数?a 2 #include 3 #include 4 using namespace std; 5 typedef long long ll; 6 const int maxn = 1000005; 7 bool is_prime[maxn]; 8.....
分类:
其他好文 时间:
2015-05-19 22:28:23
阅读次数:
203
http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=34870求n内的素数个数。 1 /* *********************************************** 2 Author : zch ...
分类:
其他好文 时间:
2015-05-19 18:17:50
阅读次数:
292
科普篇:筛法是一种简单检定素数的算法。据说是古希腊的埃拉托斯特尼(Eratosthenes,约公元前274~194年)发明的,又称埃拉托斯特尼筛法(sieve of Eratosthenes). 说实话,之前我在求质数的场合都是验证某一数是否为质数的,用定义求即可方便的得出结论,代码如下: 01: ...
Problem defineWe want to find all the primes between 2~N, then how to find all the primes efficiently?Sieve of EratosthenesSieve of Eratosthenes method, is very efficient, the algorithm is:
Create a li...
分类:
其他好文 时间:
2015-05-15 17:39:24
阅读次数:
129
题目描述:
Description:
Count the number of prime numbers less than a non-negative number, n
click to show more hints.
思路:利用厄拉多塞筛法。具体操作:先将 2~n 的各个数放入表中,然后在2的上面画一个圆圈,然后划去2的其他倍数;第一个既未画圈又没有被划去的数是3,将它画圈,...
分类:
其他好文 时间:
2015-05-11 16:08:03
阅读次数:
126
分析:筛法的思想,首先记录每个值的坐标,在使用筛法。
#include
using namespace std;
int a[10005];
int f[10005];
int main()
{
int i,n,j,mx,ans,tmp;
ios::sync_with_stdio(false);
while(cin>>n)
{
mx=-1;
memset(f,-1,size...
分类:
其他好文 时间:
2015-05-11 14:49:13
阅读次数:
145
//筛法求区间[0,n]的所有素数,v为素数表 //v[i]==0,i为素数void f(int n) { int m=sqrt(n+0.5); memset(v,0,sizeof(v)); for (int i=2;i<=m;i++) if (!v[i]) for ...
分类:
其他好文 时间:
2015-05-10 11:19:57
阅读次数:
115
1.算法简介1.1筛法起源筛法是一种简单检定素数的算法。据说是古希腊的埃拉托斯特尼(Eratosthenes,约公元前274~194年)发明的,又称埃拉托斯特尼筛法(sieve of Eratosthenes)。...
分类:
其他好文 时间:
2015-05-09 15:06:16
阅读次数:
434
埃氏筛法/*用“埃氏筛法”求2~1/*00以内的素数。2~100以内的数,先去掉2的倍数,再去掉3的倍数,再去掉4的倍数,……依此类推,最后剩下的就是素数。*/package week_1;public class Sushu { public static void main(String[] a...
分类:
其他好文 时间:
2015-05-07 20:19:47
阅读次数:
609
1022: A simple math problem 2
时间限制: 1 Sec 内存限制: 128 MB
提交: 73 解决: 13
[提交][状态][讨论版]
题目描述
高斯函数: [x]表示,小于等于x的最大整数,即向下取整。 如 [2.5]=2,[1.2]=1等。 定义函数f(n)=[n/1]+[n/2]+[n/3]+...+[n/n] . sum(a,b)=f(a...
分类:
其他好文 时间:
2015-05-07 06:30:49
阅读次数:
228