码迷,mamicode.com
首页 >  
搜索关键字:primes    ( 339个结果
PAT1015 Reversible Primes
题目:PAT1015 题解:一道不多难的题,就是麻烦了点,把其中的细节处理好就行。 首先要搞清楚问的是什么:给你一个十进制的数n,然后让你取n在d进制下的反序数并转换为10进制(这里假设为n1),问n和n1是否都为素数。 所以我大概就写了检查是否为素数的函数,转换进制的函数以及取反序的函数。 刚开始 ...
分类:其他好文   时间:2017-03-06 20:29:46    阅读次数:176
[leetcode]204. Count Primes
统计小于n的素数的个数 如果判断每一个数是不是素数的话,时间会超时,如下 题意要统计素数的个数,那么可以换一种思路,每发现一个素数i,那么i^2,i^2+i...都肯定不是素数 ...
分类:其他好文   时间:2017-03-05 20:46:57    阅读次数:126
UVa 11105 semi-prime H-numbers
方法:素数筛选 素数筛选法的推广。先求出H-primes, 可以证明得到,任意两个H-prime相乘,结果都是semi-prime H-number。求出范围内所有semi-primes,预处理前缀和即可。 (这里用到一种O(n) 素数筛选的方法) code: ...
分类:其他好文   时间:2017-01-30 10:40:27    阅读次数:215
Summation of primes
problem 10:Summation of primes 题意:求不大于200w的素数和 代码如下: 其中,int getPrime(int n,int *p,bool *vis)修改为: 1 int getPrime(int n,int *p,bool *vis){ 2 int k=0; 3 ...
分类:其他好文   时间:2017-01-17 21:19:49    阅读次数:175
Leetcode 313. super ugly number
Write a program to find the nth super ugly number. Super ugly numbers are positive numbers whose all prime factors are in the given prime list primes ...
分类:其他好文   时间:2016-12-02 14:12:22    阅读次数:167
[UVa1213]Sum of Different Primes(递推,01背包)
题目链接:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=3654 题意:把n拆成k个不同素数的和,有多少种拆法。 dp(i,j)表示数字为i时,有j个不同 ...
分类:其他好文   时间:2016-11-24 11:44:43    阅读次数:183
Leetcode problem-204 Count Primes 题解
Leetcode problem-204 Count Primes Count the number of prime numbers less than a non-negative number, n. 题解:这道题如果对每个小于n的数都进行判断是否为素数并计数会超时,因此采用筛法来解这题。建一 ...
分类:其他好文   时间:2016-11-14 15:07:32    阅读次数:102
算法题解之math类题
Count Primes 质数计数 思路1:暴力法。其中判断每一个数n是不是质数需要验证是否任何小于n的数都不能整除n,这一步是O(n)。因此整体复杂度是O(n^2)。 思路2:思路1的优化版。如果一个数n不是质数,则n = p * q。令 p <= q,则可以推出 p * p <= n,即 p < ...
分类:编程语言   时间:2016-11-13 16:57:36    阅读次数:165
hdu 5901 Count primes 素数计数模板
转自:http://blog.csdn.net/chaiwenjun000/article/details/52589457 计从1到n的素数个数 两个模板 时间复杂度O(n^(3/4)) 第二个 时间复杂度O(n^(2/3)) ...
分类:其他好文   时间:2016-11-08 20:05:53    阅读次数:214
Count Primes
Description: Count the number of prime numbers less than a non-negative number, n. ...
分类:其他好文   时间:2016-10-08 13:51:47    阅读次数:136
339条   上一页 1 ... 11 12 13 14 15 ... 34 下一页
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!