Algorithm,Number Theory,Prime
2013-07-24 13:14
183 查看
/***************************************************/ // 测素数,根号阶 bool is_prime(int u) { if(u == 0 || u == 1) return false; if(u == 2) return true; if(u%2 == 0) return false; for(int i=3; i <= sqrt(u) ;i+=2) if(u%i==0) return false; return true; } /***************************************************/ // 线性筛素数 const int M = 1000; // M : size bool mark[M]; // true : prime number void sieve_prime() { memset(mark, true, sizeof(mark)); mark[0] = mark[1] = false;// 0 not used, 1 is not prime for(int i=2; i <= sqrt(M) ;i++) {// 2-> 4, 6, 8, ... //3->9, 12, 15...// 5->25, 30, ... if(mark[i]) { for(int j=i*i; j < M ;j+=i) mark[j] = false; } } }
相关文章推荐
- [the summarization of algorithm]How to list the prime number
- Number Theory 4.3 Prime Examples
- algorithm@ Sieve of Eratosthenes (素数筛选算法) & Related Problem (Return two prime numbers )
- Algorithm,Number Theory,GCD
- Coursera Algorithms, Part 1 Week 1: Analysis of Algorithm
- 获400 万美元 A 轮融资,ShipBob 想帮助小微企业享受Amazon Prime 级配送服务 2016-06-18
- HDOJ 1016 Prime Ring Problem
- Quartus Prime 16.1 和Modelsim 16.1联合(二)仿真测试
- A novel Bayesian network inference algorithm for integrative analysis of deep sequencing data
- Prime Number of Set Bits in Binary Representation
- 线性时间冰山查询算法(Linear-time Iceberg Query Algorithm )
- 762. Prime Number of Set Bits in Binary Representation
- [c++,algorithm] 哈密尔顿回路判断
- POJ 3126 Prime Path(bfs)
- CORDIC algorithm
- CSP认证训练题——Coprime Sequence HDU - 6025
- HDU 1016 Prime Ring Problem
- 【POJ】3126-Prime Path BFS、剪枝技巧
- Codeforces Round #278 (Div. 2) B. Candy Boxes [brute force+constructive algorithms]
- [Java] 绕过证书验证调 HTTPS 接口时报 “SSLHandshakeException: DHPublicKey does not comply to algorithm constraints”的解决办法