码迷,mamicode.com
首页 >  
搜索关键字:prime    ( 2475个结果
leetcode Count Primes 204
leetcode Count Primes 204 Sieve of Eratoasthenes...
分类:其他好文   时间:2015-05-21 10:52:07    阅读次数:123
【leetcode】Count Primes(easy)
Count the number of prime numbers less than a non-negative number,n思路:数质数的个数开始写了个蛮力的,存储已有质数,判断新数字是否可以整除已有质数。然后妥妥的超时了(⊙v⊙)。看提示,发现有个Eratosthenes算法找质数的,说...
分类:其他好文   时间:2015-05-21 10:47:58    阅读次数:110
hdoj - 1258 Sum It Up && hdoj - 1016 Prime Ring Problem (简单dfs)
http://acm.hdu.edu.cn/showproblem.php?pid=1258关键点就是一次递归里面一样的数字只能选一次。 1 #include 2 #include 3 4 int n,t; 5 int b[15],c[15]; 6 bool flag; 7 void dfs(...
分类:其他好文   时间:2015-05-21 10:20:53    阅读次数:151
素数高效率筛选法
无需多言直接上代码吧! 1 //Eratosthenes 筛法(埃拉托斯特尼筛法) 2 memset(check, false, sizeof(check)) 3 int tot = 0; 4 for(int i=2; iN) break;21 check[i*prime[j]] ...
分类:其他好文   时间:2015-05-20 22:17:16    阅读次数:227
[HDOJ1016]Prime Ring Problem
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1016原题:A ring is compose of n circles as shown in diagram. Put natural number 1, 2, ..., n into each ci...
分类:其他好文   时间:2015-05-20 00:11:30    阅读次数:138
区间素数筛法
给定整数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
AOJ - 0009 Prime Number (素数筛法) && AOJ - 0005 (求最大公约数和最小公倍数)
http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=34870求n内的素数个数。 1 /* *********************************************** 2 Author : zch ...
分类:其他好文   时间:2015-05-19 18:17:50    阅读次数:292
__周赛(最小生成树(Prime))
将已经链接的边的权值设为0即可。但是可能会超时,提交的时候,有一次显示超时,所以这个解法是有问题的,看到有171ms的,实力差的太大了,还是得使劲刷题。/*2015-5-18 951ms*/#include#include#includeusing namespace std;#define INF...
分类:其他好文   时间:2015-05-18 22:24:24    阅读次数:165
Prime Path--POJ3126(dfs)
DescriptionThe ministers of the cabinet were quite upset by the message from the Chief of Security stating that they would all have to change the four...
分类:其他好文   时间:2015-05-18 20:13:06    阅读次数:139
LeetCode--Count Primes
Count the number of prime numbers less than a non-negative number,n.1.常规思路(计算复杂度为O(n*sqrt(n))),提交后超时。public static boolean isPrime(int m){ bool...
分类:其他好文   时间:2015-05-18 10:32:38    阅读次数:90
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!