题意:
给一个n,求出F(n)
思路:
就是求sigma(g(i))|1<=i<=n
f(i)表示与i互质的数的个数
#include<stdio.h>
#include<string.h>
#include<iostream>
#include<algorithm>
#include<math.h>
#include<queue>
#include<stack>
#include<string>
#include<vector>
#include<map>
#include<set>
using namespace std;
#define lowbit(x) (x&(-x))
typedef long long LL;
const int maxn = 100005;
const int inf=(1<<28)-1;
#define maxp 2000100
bool notprime[maxp];
int phi[maxp];
void get_phi()
{
notprime[1]=true;
for(int i=1;i<maxp;++i)
phi[i]=1;
for(int i=2;i<maxp;++i)
if(!notprime[i])
{
phi[i]*=i-1;
for(int j=i+i;j<maxp;j+=i)
{
notprime[j]=true;
int n=j/i;
phi[j]*=i-1;
while(n%i==0)
{
n/=i;
phi[j]*=i;
}
}
}
}
LL get_phi(LL n)
{
LL res=n,m=n;
for(LL i=2;i*i<=m;++i)
if(m%i==0)
{
res=res/i*(i-1);
while(m%i==0) m/=i;
}
if(m>1) res=res/m*(m-1);
return res;
}
LL Sum[maxp];
int main()
{
get_phi();
for(int i=2;i<maxp;++i)
Sum[i]=Sum[i-1]+phi[i];
int n;
while(~scanf("%d",&n)&&n)
{
printf("%lld\n",Sum[n]);
}
return 0;
}