# Bzoj2440 [中山市选2011]完全平方数

Posted by yjjr's blog on December 14, 2017

# 题目

Description

1

13

100

1234567 Sample Output 1

19

163

2030745 HINT

, T ≤ 50

# 分析

$sum=\sum_{i=1}^{\sqrt x} \mu(i) \lfloor x/i^2\rfloor$

# code

#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#define rep(i,a,b) for(ll i=a;i<=b;i++)
#define dep(i,a,b) for(ll i=a;i>=b;i--)
#define ll long long
#define mem(x,num) memset(x,num,sizeof x)
#define inf 1844387848
using namespace std;
{
ll f=1,x=0;char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
return x*f;
}
const int maxn=50006;
ll cnt=0,mu[maxn],prime[maxn];
bool is_prime[maxn];

void getmu()
{
mu[1]=1;
rep(i,2,maxn-6){
if(!is_prime[i])prime[++cnt]=i,mu[i]=-1;
rep(j,1,cnt){
if(prime[j]*i>maxn-6)break;
is_prime[i*prime[j]]=1;
if(i%prime[j]==0){mu[i*prime[j]]=0;break;}
else mu[i*prime[j]]=-mu[i];
}
}
}

ll cal(ll x)
{
ll sum=0, t=sqrt(x);
rep(i,1,t)sum+=x/(i*i)*mu[i];
return sum;
}

int main()
{
getmu();
while(Que--){