bzoj2440完全平方数

$$\sum^{ \lfloor \sqrt{x} \rfloor}_{i=1} \frac{x}{i^{2}}*\mu(x)$$

/**************************************************************
Problem: 2440
User: zhangheran
Language: C++
Result: Accepted
Time:4648 ms
Memory:6560 kb
****************************************************************/

#include<iostream>
#include<cstdio>
#include<algorithm>
//#include"suqingnian.h"
using namespace std;

int mu[600100];
const int __n=56000;
bool __check[600010];
int __size;
int _num[600010];
void _prime()
{
for(int _i=2;_i<=__n;_i++)
{
if(!__check[_i]) _num[++__size]=_i,mu[_i]=-1;
for(int _j=1;_j<=__size;_j++)
{
if(_i*_num[_j]>=__n) break;
__check[_num[_j]*_i]=1;
if(_i%_num[_j]==0) {mu[_i*_num[_j]]=0;break;}
mu[_i*_num[_j]]=mu[_i]*mu[_num[_j]];
}
}
mu[1]=__check[1]=1;
return ;
}
//    bool _isprime(int __n) {return ~__check[__n];}

int t;
long long k;
long long calc(long long x)
{

long long sum=0;
for(long long i=1;i*i<=x;i++)
sum+=x/(i*i)*mu[i];
//  printf("%lld %lld\n",x,sum);
return sum;
}
//long long che(long long l,long long r,long long)
//{
//
//}
long long hint(long long x)
{
long long ans=0;
long long l=x,r=1644934081;
while(l<=r){
//      printf("%lld %lld\n",l,r);
long long mid=l+r>>1;
//      printf("%lld \n",calc(mid));
if(calc(mid)>=x) ans=mid,r=mid-1;
else l=mid+1;
}return ans;
}
int main()
{
scanf("%d",&t);
_prime();
while(t--)
{
scanf("%lld",&k);
printf("%lld\n",hint(k));
}
}

posted @ 2018-07-25 00:04  米罗偕涯  阅读(328)  评论(0编辑  收藏  举报