随笔分类 - 素数
摘要:这个是求互质的数的个数:我们知道Eular n = a1^p1*a2^p2*...an^pn;那么它的质因子个数为 num = (p1 + 1)*(p2 + 1) *...*( pn +1 );那么它互质的数的个数为 num= ( 1 - 1/a1 )*(1 - 1/a2)*...*( 1 - 1/an )*n;View Code #include<iostream>#include<cstdio>#include<cstdlib>#include<algorithm>#include<cmath>#include<queue&
阅读全文
摘要:这个题是对欧拉函数的运用题意:就是给出一个奇素数,求出他的原根的个数。定义:n的原根x满足条件0<x<n,并且有集合{ (xi mod n) | 1 <= i <=n-1 } 和集合{ 1, ..., n-1 }相等定理:如果p有原根,则它恰有φ(φ(p))个不同的原根,p为素数,当然φ(p)=p-1,因此就有φ(p-1)个原根;View Code #include<iostream>#include<cstdio>#include<cstdlib>#include<algorithm>#include<cmath&
阅读全文
摘要:一个对Miller_rabin与pallord的一个运用;View Code #include<iostream>#include<cstdio>#include<cstdlib>#include<algorithm>#include<cmath>#include<queue>#include<set>#include<map>#include<cstring>#include<vector>#define LL unsigned long longusing namespa
阅读全文
摘要:首先利用miller_rabin测试是否为素数;再利用pallord进行质因子分解;View Code #include<iostream>#include<cstdio>#include<cstdlib>#include<cmath>#include<algorithm>#define LL unsigned long longusing namespace std;LL p[10] = { 2,3,5,7,11,13,17,19,23,29 };int cnt = 0; LL num[100];LL Multi( LL a , L
阅读全文
摘要:这个题用到Miller_rabin与pallord算法:View Code #include<iostream>#include<cstdio>#include<cstdlib>#include<algorithm>#include<cmath>#include<queue>#include<set>#include<map>#include<cstring>#include<ctime>#include<vector>#define LL long long u
阅读全文
摘要:这个其实比较水,只是用到了一个同余定理,还有一个素数二重筛选;View Code #include<iostream>#include<cstdio>#include<cstdlib>#include<algorithm>#include<cmath>#include<queue>#include<set>#include<map>#include<cstring>#include<vector>using namespace std;int prime[10000],cnt
阅读全文
摘要:素数水题:View Code #include<iostream>#include<cstdio>#include<cstdlib>#include<algorithm>#include<cmath>#include<queue>#include<set>#include<map>#include<cstring>#include<vector>using namespace std;int prime[10000],cnt=0;bool hash[100024];void
阅读全文
摘要:题意:给定你一个数n,让你求出1-n内有多少个素数,再给你一个数d,如果2*d大于素数的个数则全部输出;否则,如果个数为单数,输出2*d - 1个并且以中间那个素数为中心分别向两边输出d-1个;如果偶数个,输出2*d个,也是以中间那个素数为中心向两边扩展;View Code #include<iostream>#include<cstdio>#include<cstdlib>#include<algorithm>#include<cmath>#include<queue>#include<set>#includ
阅读全文
摘要:一道素数与BFS结合的题;View Code View Code #include<iostream>#include<cstdio>#include<cstdlib>#include<algorithm>#include<cmath>#include<queue>#include<set>#include<map>#include<cstring>#include<vector>using namespace std;class que{public: int num; i
阅读全文
摘要:素数水题:View Code #include<iostream>#include<cstdio>#include<cstdlib>#include<algorithm>#include<cmath>#include<queue>#include<set>#include<map>#include<cstring>#include<vector>using namespace std;int prime[100000],cnt=0;bool hash[700024];void
阅读全文
摘要:一道简单的素数题:View Code #include<iostream>#include<cstdio>#include<cstdlib>#include<algorithm>#include<cmath>#include<queue>#include<set>#include<map>#include<cstring>#include<vector>using namespace std;int prime[100000],cnt=0;bool hash[1000024]
阅读全文
摘要:求一个数能够被连续的素数的和组成有几种方法:直接用暴力;View Code #include<iostream>#include<cstdio>#include<cstdlib>#include<algorithm>#include<cmath>#include<cstring>using namespace std;int prime[2024],cnt,sum;void Prime( ){ bool hash[5024] = { 0 }; int t = ( int )sqrt( 10000.0 ) + 1; for(
阅读全文
摘要:题意:给定你一个以质数为底表示的数;问你这个数减1,之后用质数为底的表示法。例如:17 1 = 17^1 =17 - 1;5 1 2 1 = 5^1*2^1=10 - 1;2 4= 2^4 = 163 2 = 3^2= 9;View Code #include<iostream>#include<cstdio>#include<cstdlib>#include<algorithm>#include<cmath>#include<cstring>using namespace std;int prime[4024],cnt;
阅读全文
摘要:题意:输入m, n, d。求出m,m+1,m+2,````m+n的一个排列。使得任意的连续k个数之和都为合数,2<=k<=d。注意如果开始时连续数小于d时也要是合数;用DFS暴力搜索;View Code #include<iostream>#include<cstdio>#include<cstdlib>#include<algorithm>#include<cmath>#include<cstring>using namespace std;int num[1024],S,E,d;;bool visit[10
阅读全文
摘要:该题WA了上午,呜呜.......最后,幸亏lvsi的提醒,把getsum函数改为long long 型就过了,该题与poj 2992 Divisors是同一类型这里我们就不累叙了,这里要注意的就是2与5的对数,我们就把2与5成对处理掉,因为2*5=10,我们就可以忽略2与5成对的情况; 1 #include<stdio.h> 2 #include<stdlib.h> 3 #include<math.h> 4 #include<string.h> 5 int hash[500024]={0}; 6 int prime[100000]; 7 int
阅读全文
摘要:#include<stdio.h>#include<string.h> #include<stdlib.h>int Prime( int prime[] ){ int i,j,count=0; for( int i=2;i<=500;i++ ) { int j=2,t=i/2; for( ;j<=t;j++ ) if( i%j==0 ) break; if( j==( t+1 ) ) { prime[count++]=i; } } return count;}in...
阅读全文
摘要:素数筛选法一直是数论中的重点,你找到的规律越多你的筛选就越快。先让我们 看一个算法:#include<stdio.h>#include<math.h>#define MAX_P 500int nList[MAX_P] = {0};void Calc(){ int n,p,t,sq=(int)sqrt(MAX_P*2+1); for (n=3;n<=sq;n+=2) { if (nList[n>>1]) continue; for (t=n*n;t<=MAX_P<<1;t+=n<<1) //筛选循环 nList[t>&
阅读全文
摘要:Description我们知道,任何一个大于1的数,都可以写成多个素数的乘积,我们把这些素数叫做这个数的素因子。Input第一行为测试数据的组数N,以下N行,每行一个数字k(1<k<2^24)Output输出N行,每行两个数字,一个是k的最大素因子,第二个是k的素因子的个数。Sample Input3 10 25 120Sample Output52 5 1 5 3代码:#include<stdio.h>#include<stdlib.h>#include<math.h>bool a[2100]={0};int num[600];int main
阅读全文

浙公网安备 33010602011771号