随笔分类 -  Algorithm---Prim Number Problems

摘要:第一眼看这道题目的时候觉得可能会很难也看不太懂,但是看了给出的Hint之后思路就十分清晰了Consider the first sample. Overall, the first sample has 3 queries.The first query l = 2, r = 11 comes. Y... 阅读全文
posted @ 2015-03-04 18:35 Jeremy Wu 阅读(190) 评论(0) 推荐(0) 编辑
摘要:bool prime(int n){ int i = 7, j, q; if(n == 1) return false; if(n == 2 || n == 5 || n == 3) return true; if(n % 2 == 0 || n % 3 == 0 || ... 阅读全文
posted @ 2015-02-14 10:44 Jeremy Wu 阅读(207) 评论(0) 推荐(0) 编辑
摘要:题目描述 Give you a lot of positive integers, just to find out how many prime numbers there are.. In each case, there is an integer N representing the num... 阅读全文
posted @ 2014-07-30 21:12 Jeremy Wu 阅读(501) 评论(7) 推荐(0) 编辑
摘要:参考自:http://blog.csdn.net/niushuai666/article/details/6973134/*遇到素数需要打表时,先估算素数的个数:num = n / lnx;num为大概数字,越大误差越小(只是估计,用于估算素数表数组大小)这个打表法效率貌似很高,网上说几乎达到了线性时间(不知道是真是假=。=)*/#include#include#include#include#includeusing namespace std;const int MAXSIZE = 10100000;int n;bool visit[MAXSIZE];int prime[MAXSIZE]; 阅读全文
posted @ 2014-04-07 10:22 Jeremy Wu 阅读(196) 评论(0) 推荐(0) 编辑

点击右上角即可分享
微信分享提示