Codeforces 955C. Sad powers

题意:

       给定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;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值