I guess the punch line of this one is Sieving for primes.#include #include #include #include #include #include #include #include using namespace std;v...
分类:
其他好文 时间:
2015-05-28 02:01:14
阅读次数:
414
题目如下:
A reversible prime in any number system is a prime whose "reverse" in that number system is also a prime. For example in the decimal system 73 is a reversible prime because its reverse 37 is al...
分类:
其他好文 时间:
2015-05-25 14:39:05
阅读次数:
140
leetcode Count Primes 204
Sieve of Eratoasthenes...
分类:
其他好文 时间:
2015-05-21 10:52:07
阅读次数:
123
Count the number of prime numbers less than a non-negative number,n思路:数质数的个数开始写了个蛮力的,存储已有质数,判断新数字是否可以整除已有质数。然后妥妥的超时了(⊙v⊙)。看提示,发现有个Eratosthenes算法找质数的,说...
分类:
其他好文 时间:
2015-05-21 10:47:58
阅读次数:
110
Sum of Different Primes
Time Limit: 5000MS
Memory Limit: 65536K
Total Submissions: 3293
Accepted: 2052
Description
A positive integer may be expressed as a sum of d...
分类:
其他好文 时间:
2015-05-19 20:56:40
阅读次数:
126
好久不练手了,注意boolean array default 是falsepublic class Solution { public int countPrimes(int n) { if(n<=2) return 0; boolean[] a = ne...
分类:
其他好文 时间:
2015-05-19 08:47:46
阅读次数:
90
判断一个数是否为质数有两种方法,一种是判断它能否被2~(int)sqrt(n)+1之间的数整除,能被整除为合数,否则为质数
但是,当n非常大的时候这种方法是非常费时间的。
另外一种改进的方法是仅用n除以2~(int)sqrt(n)+1之间的所有质数,而2~(int)sqrt(n)+1之间的质数从何而来?先计算出来
测试用例需要的小于num的所有质数的num大概为1200就能通过本题的测试用例...
分类:
其他好文 时间:
2015-05-17 15:20:04
阅读次数:
94
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
examination questionsDescription:Count the number of prime numbers less than a non-negative number, nReferences:How Many Primes Are There?Sieve of Era...
分类:
其他好文 时间:
2015-05-15 07:53:07
阅读次数:
388
题意是选择k个质数使其和为n,先搞一个素数表然后dp,dp[i][j]表示选了j个数和位i的方案数。
#include
#define foreach(it,v) for(__typeof((v).begin())it=(v).begin();it!=(v).begin();++it)
using namespace std;
typedef long long ll;
const int ma...
分类:
其他好文 时间:
2015-05-12 17:17:27
阅读次数:
113