题目:经过提炼后, 题目的意思就是问[2,n] 内,不是次方数的数量 ,;

思路:

答案就是

原理是利用容斥,注意n开i次根是向下取整(这题巨卡精度)

这是大神的思路 ,, 我还没有理解, 先放着,等以后在来思考 , 先当模板使用

#include <bits/stdc++.h>

#define forn(i, n) for (int i = 0; i < int(n); i++)

using namespace std;

const int K = ;
const int N = * + ;
const long long INF64 = 3e18; int mu[K]; void precalc(){
static bool prime[K];
static int lst[K]; memset(prime, false, sizeof(prime));
forn(i, K) lst[i] = i; for (int i = ; i < K; ++i){
if (lst[i] == i) mu[i] = ;
for (int j = * i; j < K; j += i){
lst[j] = min(lst[j], lst[i]);
if (lst[j] == lst[i])
mu[j] = ;
else
mu[j] = -mu[i];
}
}
} int mx[K]; long long binpow(long long a, int b){
long long res = ;
while (b){
if (b & ){
if (res < INF64 / a) res *= a;
else return INF64;
}
if (b > ){
if (a < INF64 / a) a *= a;
else return INF64;
}
b >>= ;
}
return res;
} long long calc(long long n){
int pw = - __builtin_clzll(n);
for (int i = ; i <= pw; ++i){
if (mu[i] == ) continue;
while (binpow(mx[i], i) > n)
--mx[i];
} long long res = n - ;
for (int i = ; i <= pw; ++i)
res -= mu[i] * (mx[i] - ); return res;
} int get_sqrt(long long n){
int l = , r = ;
while (l < r - ){
int m = (l + r) / ;
if (m * 1ll * m <= n)
l = m;
else
r = m;
}
return (r * 1ll * r <= n ? r : l);
} long long ans[N]; int main() {
precalc();
int T;
scanf("%d", &T);
vector<pair<long long, int> > q; forn(i, T){
long long n;
scanf("%lld", &n);
q.push_back({n, i});
} sort(q.begin(), q.end(), greater<pair<long long, int> >());
mx[] = ;
mx[] = ;
mx[] = ;
for (int i = ; i < K; ++i)
mx[i] = ; forn(z, T){
long long n = q[z].first;
mx[] = get_sqrt(n);
ans[q[z].second] = calc(n);
} forn(i, T)
printf("%I64d\n", ans[i]);
return ;
}

F. Relatively Prime Powers (求([2,n],内不是次方的数量)的更多相关文章

  1. SGU 231 Prime Sum 求&lt;=n内有多少对素数(a,b)使得a+b也为素数 规律题

    题目链接:contest=0&problem=231">点击打开链接 题意: 求<=n内有多少对素数(a,b)使得a+b也为素数 思路: 我们发现全部素数间隔都是> ...

  2. Educational Codeforces Round 50 (Rated for Div. 2) F - Relatively Prime Powers(数学+容斥)

    题目链接:http://codeforces.com/contest/1036/problem/F 题意: 题解:求在[2,n]中,x != a ^ b(b >= 2 即为gcd)的个数,那么实 ...

  3. Educational Codeforces Round 50 (Rated for Div. 2)F. Relatively Prime Powers

    实际上就是求在[2,n]中,x != a^b的个数,那么实际上就是要求x=a^b的个数,然后用总数减掉就好了. 直接开方求和显然会有重复的数.容斥搞一下,但实际上是要用到莫比乌斯函数的,另外要注意减掉 ...

  4. 省赛i题/求1~n内所有数对(x,y),满足最大公约数是质数的对数

    求1~n内所有数对(x,y),gcd(x,y)=质数,的对数. 思路:用f[n]求出,含n的对数,最后用sum[n]求和. 对于gcd(x,y)=a(设x<=y,a是质数),则必有gcd(x/a ...

  5. P1886 滑动窗口&&P1440 求m区间内的最小值

    声明:下面这两个题就不要暴力了,学一学单调队列吧 推荐博文:https://www.cnblogs.com/tham/p/8038828.html 单调队列入门题 P1440 求m区间内的最小值 题目 ...

  6. 省赛i题/求1~n内全部数对(x,y),满足最大公约数是质数的对数

    求1~n内全部数对(x,y),gcd(x,y)=质数,的对数. 思路:用f[n]求出,含n的对数.最后用sum[n]求和. 对于gcd(x,y)=a(设x<=y,a是质数),则必有gcd(x/a ...

  7. 洛谷 P1440 求m区间内的最小值

    传送门 思路 由于数据范围很大,所以使用单调队列,和滑动窗口这道题类似 首先第一个数输出\(0\),因为第一个数之前没有数 然后通过样例我们发现,最后一个数并没有派上什么用场,所以循环\(n-1\)轮 ...

  8. Relatively Prime Powers CodeForces - 1036F (莫比乌斯函数容斥)

    Relatively Prime Powers CodeForces - 1036F Consider some positive integer xx. Its prime factorizatio ...

  9. LG1440 求 m 区间内的最小值

    题目描述 一个含有 \(n\) 项的数列 (\(n≤ 2000000\)),求出每一项前的 \(m\) 个数到它这个区间内的最小值.若前面的数不足 \(m\) 项则从第 \(1\) 个数开始,若前面没 ...

随机推荐

  1. 9th

    2017-2018-2 20179212<网络攻防实践>第9周作业 视频学习 KaliSecurity压力测试工具 压力测试通过确定一个系统的瓶颈或者不能接受的性能点,来获得系统能够提供的 ...

  2. [转]基于phantomJS实现web性能监控

    1.web性能监控背景描述 上期分享的<Web性能监控自动化探索之路–初识WebPageTest>从依赖webpagetest的角度给出了做性能日常检查的方案,但由于依赖结构相对复杂我们需 ...

  3. Guice总结

    Guice总结 Jar包:guice-4.1.0.jar 辅包: guava-15.0.jar aopalliance-.jar javaee-api-6.0-RC2.jar Guice的IoC 两种 ...

  4. 安装phpredis

    1.下载安装包 https://github.com/nicolasff/phpredis/archive/2.2.5.tar.gz 2.解压到~目录 tar -xvf phpredis-2.2.5. ...

  5. MySQL数据库服务器参数优化mycnf,16G内存8核CPU,

    业务场景: 后台支持手机在线更新系统,db服务器内存16G,8核,dell的pc服务器. qps: 200个左右 tps: 1个左右 一分钟50几个 sort_buffer_size = 32M 大了 ...

  6. Poj 1504 Adding Reversed Numbers(用字符串反转数字)

    一.题目大意 反转两个数字并相加,所得结果崽反转.反转规则:如果数字后面有0则反转后前面不留0. 二.题解 反转操作利用new StringBuffer(s).reverse().toString() ...

  7. HDU1698(线段树入门题)

    Just a Hook Time Limit:2000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Descrip ...

  8. Canal入门

    配置mysql 1.mysql开启binlog mysql默认没有开启binlog,修改mysql的my.cnf文件,添加如下配置,注意binlog-format必须为row,因为binlog如果为S ...

  9. 办公软件-Excel:Excel百科

    ylbtech-办公软件-Excel:Excel百科 Microsoft Excel是Microsoft为使用Windows和Apple Macintosh操作系统的电脑编写的一款电子表格软件.直观的 ...

  10. Python-RabbitMQ消息队列的发布与订阅

    RabbitMQ消息队列的发布与订阅类似于广播,一端发送消息,多个客户端可以同时接收到消息 fanout:所有绑定到exchange的queue都可以接收消息 消息发布端 # -*- coding:u ...