您的位置:首页 > 其它

Codeforces 955C. Sad powers

2018-03-26 20:59 411 查看


题意:
       给定L,R,求[L,R]内有多少个数x满足存在a>0,p>1使得x=a^p。
题解:
       明明很简单的一道题,比赛的时候意识模糊被卡精+卡常卡到死。
       记f(x)为[1,x]的答案,a[i]表示x以内,i次方数的个数,然后暴力莫比乌斯函数跑容斥就OK。
       说说死在哪里了:这题的log是1e18的,如果求a[i]的时候用二分会TLE(开O(松)的请自觉忽视),直接使用pow会WA掉。那么只要开long double,然后pow(x+0.1,1/p)就好了啊!!!
       刚刚发现的时候感觉自己是____#pragma GCC optimize(2)
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<cmath>
#include<cstdio>
#include<time.h>
#include<vector>
#include<cstring>
#include<stdlib.h>
#include<iostream>
#include<algorithm>
#define LL long long
#define R register
using namespace std;
const int N=1e5+10;
const int mod=1e9+7;
const int inf=0x3f3f3f3f;
const double eps=1e8;

int Q,mu[150];
LL L,RR,a[100];

namespace FastIO {
// #define DEBUG
static const int MAX_SIZE = 1 << 15;
char *l, *r;
static char buf[MAX_SIZE];
inline int gc() {
if(l == r) if(l == (r = (l = buf) + fread(buf, 1, MAX_SIZE, stdin))) return -1;
return *l ++;
}
template<typename tp> inline void read(tp &x) {
x = 0;char c = gc();bool f = 0;
for(; c < '0' || c > '9'; f |= (c == '-'), c = gc());
for(; c >= '0' && c <= '9'; x = (x << 3) + (x << 1) + c - '0', c = gc());
if(f) x = -x;
}
}
using namespace FastIO;

LL Getnum(LL p,long double x) {
return max((long double)0.0,pow(x+0.1,1.0/p)-1);
}

LL Solve(LL x) {
if (x==0) return 0;
for (R int i=1;i<=60;i++) a[i]=0;
a[1]=1;
for (R int i=2;i<=60;i++) {
a[i]=Getnum(i,x);
if (!a[i]) break;
}
LL ans=0;
for (R int i=1;i<=60;i++) ans-=a[i]*mu[i];
return ans;
}

void sieve(){
mu[1]=1;
for(R int i=1;i<=100;i++){
for(R int j=2*i;j<=100;j+=i){
mu[j]-=mu[i];
}
}
mu[1]=-1;
}

int main() {
// freopen("data.in","r",stdin);
read(Q);
sieve();
while (Q--) {
read(L); read(RR);
printf("%lld\n",Solve(RR)-Solve(L-1));
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: