数论模版-欧拉函数、莫比乌斯函数和素数

/*Author:WNJXYK*/
#include<cstdio>
#include<iostream>
#include<cstring>
#include<string>
#include<algorithm>
#include<queue>
#include<set>
#include<map>
using namespace std;

#define LL long long
#define Inf 2147483647
#define InfL 10000000000LL

inline void swap(int &x,int &y){int tmp=x;x=y;y=tmp;}
inline void swap(LL &x,LL &y){LL tmp=x;x=y;y=tmp;}
inline int remin(int a,int b){if (a<b) return a;return b;}
inline int remax(int a,int b){if (a>b) return a;return b;}
inline LL remin(LL a,LL b){if (a<b) return a;return b;}
inline LL remax(LL a,LL b){if (a>b) return a;return b;}

const int Maxn=10000000;


LL prime[Maxn/2+10];
bool valid[Maxn+10];
int primes;
inline void getPrime(){
	memset(valid,true,sizeof(valid));
	for (int i=2;i<=Maxn;i++){
		if (valid[i])prime[++primes]=i;
		for (int j=1;j<=primes && prime[j]*i<=Maxn;j++){
			valid[prime[j]*i]=false;
			if (i%prime[j]==0) break;
		}
	}
}


LL miu[Maxn+10];
inline void getMiu(){
	for (int i=1;i<=Maxn;i++){
		int target=(i==1?1:0);
		int delta=target-miu[i];
		miu[i]=delta;
		for (int j=i+i;j<=Maxn;j+=i) miu[j]+=delta;
	}
}

LL phi[Maxn+10];
LL minDiv[Maxn+10];
LL sum[Maxn+10];
inline void getPhi(){
	for (int i=1;i<=Maxn;i++) minDiv[i]=i;
	for (int i=2;i<=i*i;i++)
		if (minDiv[i]=i)
			for (int j=i*i;j<=Maxn;j+=i)
				minDiv[j]=i;
	phi[1]=1;
	for (int i=2;i<=Maxn;i++){
		phi[i]=phi[i/minDiv[i]];
		if ((i/minDiv[i])%minDiv[i]==0){
			phi[i]*=minDiv[i];
		}else{
			phi[i]*=minDiv[i]-1;
		}
	}
}

/*
int primes,prime[Maxn],mu[Maxn],g[Maxn],sum[Maxn];
void getPrime_Miu_G_S(){
    static bool vis[Maxn];
    memset(vis,0,sizeof(vis));
    mu[1]=1;primes=0;
    for(int i=2;i<Maxn;i++){
        if(!vis[i])
            prime[primes++]=i,mu[i]=-1,g[i]=1;
        for(int j=0;j<primes&&i*prime[j]<Maxn;j++){
            vis[i*prime[j]]=1;
            if(i%prime[j])
                mu[i*prime[j]]=-mu[i],g[i*prime[j]]=mu[i]-g[i];
            else{ 
<span style="white-space:pre">				</span>mu[i*prime[j]]=0;g[i*prime[j]]=mu[i];break;}
        }
    }
    sum[0]=0;
    for(int i=1;i<Maxn;i++)
        sum[i]=sum[i-1]+g[i];
}*/

int main(){

	return 0;
}

posted @ 2014-10-28 12:00  WNJXYK  阅读(178)  评论(0编辑  收藏  举报

WNJXYK-我今年一定要努力!