码迷,mamicode.com
首页 >  
搜索关键字:prime    ( 2475个结果
CD0J/POJ 851/3126 方老师与素数/Prime Path BFS
Prime PathTime Limit:1000MSMemory Limit:65536KTotal Submissions:9982Accepted:5724Description The ministers of the cabinet were quite upset by the mess...
分类:其他好文   时间:2015-01-14 10:59:08    阅读次数:143
HDU 1016 Prime Ring Problem
这题我用的是DFS。不多说,看代码和注释。 #include #include #include #include #include using namespace std;//因为n<20,所以最大的素数也就是40左右,因此用一个数组来记录45以内的素数,用于之后的判定。 bool isprime[45]={0,1,1,1,0,1,0,1,0,0,0,1,0,1,0,0,0,1,0,1,0,0...
分类:其他好文   时间:2015-01-13 23:19:53    阅读次数:246
1090. Highways
#include "iostream" #include "memory.h" #include "cstdio" using namespace std; int grap[500][500]; int ans; int dis[500]; bool visited[500]; void prime(int n){ int source = 1; for (int i = 1; i <=...
分类:其他好文   时间:2015-01-13 21:39:05    阅读次数:153
Prime Numbers in a Grid素数网格
&/@Shorthand notation for MapIf[PrimeQ[#], Framed@Style[#, Orange, Bold, 15], #] & /@ Range[250]Grid@Partition[If[PrimeQ[#], Tooltip[Framed@Style...
分类:其他好文   时间:2015-01-12 22:16:57    阅读次数:143
[Hackerrank] Prime Number Less Than N
static int getNumberOfPrimes(int N) { int n = N+1;//to include 0 as the first number for easy index operations later final boolean a[] =...
分类:其他好文   时间:2015-01-09 01:31:29    阅读次数:458
hdu4135--Co-prime(欧拉函数+容斥原理)
Co-prime Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submit Status Appoint description:  System Crawler  (2015-01-07) Description Given a number N, y...
分类:其他好文   时间:2015-01-08 22:52:22    阅读次数:314
HDU 4135 Co-prime (容斥原理+质因数分解)
这题只要知道质因数的性质就很容易做了。任意一个正整数(除了1)都可以分解成有限个质数因子的乘积。 那么假如两个数互质,那么这两个数肯定至少各有一个对方没有的质因子。所以若一个数跟n不互质,那么这个的数的质因子肯定也都属于n的质因子,那么就用容斥原理求出所有跟n不互质的所有数的个数。然后再用总的减去即可。 代码如下: #include #include #include #include...
分类:其他好文   时间:2015-01-08 18:11:23    阅读次数:234
HDU 4135 Co-prime(组合+容斥)
Problem Description Given a number N, you are asked to count the number of integers between A and B inclusive which are relatively prime to N. Two integers are said to be co-prime or relatively pr...
分类:其他好文   时间:2015-01-06 23:11:11    阅读次数:171
UVa 10539 (筛素数、二分查找) Almost Prime Numbers
题意:求正整数L和U之间有多少个整数x满足形如x=pk 这种形式,其中p为素数,k>1分析:首先筛出1e6内的素数,枚举每个素数求出1e12内所有满足条件的数,然后排序。对于L和U,二分查找出小于U和L的最大数的下标,作差即可得到答案。 1 #include 2 #include 3 #incl.....
分类:其他好文   时间:2015-01-06 21:15:02    阅读次数:131
UVa 1210 (高效算法设计) Sum of Consecutive Prime Numbers
题意:给出n,求把n写成若干个连续素数之和的方案数。分析:这道题非常类似大白书P48的例21,上面详细讲了如何从一个O(n3)的算法优化到O(n2)再到O(nlogn),最后到O(n)的神一般的优化。首先筛出10000以内的素数,放到一个数组中,然后求出素数的前缀和B。这样第i个素数一直累加到第j个...
分类:编程语言   时间:2015-01-06 00:47:52    阅读次数:187
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!