12.5
1)a|b && b|c ->a|c
2)pi(x) pi(x)~=x/ln x;
3)gcd(a,b,c)=gcd((a,b),c)=gcd(a,(b,c))
lcm(a,b,c)=lcm((a,b),c)=lcm(a,(b,c));
4)(a,b)可以写成a,b的线性表示;
5)(a,b)[a,b]=ab
6)(a,b)=(r,a);r=b%a;
7)n=p1a1p2a2p3a3……;
pi为质数(1<=i<=s),a为整数
pi<pi+1(1<=i<=s);
for(int i=2;ii<=n;i++)
if(p[i])
for(int j=i*i;j<=n;j+=i)
p[j]=0;
埃氏筛法
vector a;
bool p[100000]={0};
for(int i=2;i<=n;i++)
if(!p[i])
a.push_back(i);
for(int j=0;j<a.size();j++)
if(a[j]*i>n)break;
p[a[j]*i]=1;
if(a[j]%i==0)break;
欧氏筛法(线性筛)
归并排序
void p1(int a[],int ta[],int left,int mid,int right)
{
int l_p=left;
int r_p=mid+1;
int p=left;
while(l_p<=mid&&r_p<=right)
{
if(a[l_p]<a[r_p])ta[p++]=a[r_p];
else ta[p++]=a[r_p++];
}
while(l_p<=mid)
ta[p++]=a[l_p++];
while(r_p<=right)
ta[p++]=a[r_p++];
while(left<=right)
{
a[left]=ta[left];left++;
}
}
void p2(int a[],int ta[],int left,int right)
{
if(left<right)
{
int mid=(left+right)/2;
p2(a,ta,left,mid);
p2(a,ta,mid+1,right);
p1(a,ta,left,mid,right);
}
}
void merge_sort(int a[],int n)
{
intta=(int)mallco(n*sizeof(int));
if(ta)
{
p2(a,ta,0,n-1);
free(ta);
}
}
快速排序
int p1(int a[],int left,int right)
{
int i=left-1;
int j=right;
int p=a[right];
while(1)
{
while(a[++i]<p);
while(a[–j]>p);
if(i<j)swap(&a[i],&a[j]);
else break;
}
swap(&a[i],&a[right]);//基准放至中间
return 1;
}
void qsort(int a[],int left ,int right)
{
if(left<right)
{
int mid=p1(a,left,right);
qsort(a,left,mid-1);
qsort(a,mid+1,right);
}
}