题目链接:http://codeforces.com/contest/1036/problem/F

题意:

题解:求在[2,n]中,x != a ^ b(b >= 2 即为gcd)的个数,那么实际上就是要求x = a ^ b的个数,然后用总数减掉就好了,答案即为。(pow会丢失精度,学习避免精度丢失的方法)

 #include <bits/stdc++.h>
using namespace std;
#define ll long long
#define LL __int128
#define ull unsigned long long
#define mst(a,b) memset((a),(b),sizeof(a))
#define mp(a,b) make_pair(a,b)
#define pi acos(-1)
#define pii pair<int,int>
#define pb push_back
const int INF = 0x3f3f3f3f;
const double eps = 1e-;
const int MAXN = 1e5 + ;
const int MAXM = 2e6 + ;
const ll mod = 1e9 + ; bool check[];
int prime[];
int mu[]; void Moblus(int N) {
mst(check, false);
mu[] = ;
int tot = ;
for(int i = ; i <= N; i++) {
if(!check[i]) {
prime[tot++] = i;
mu[i] = -;
}
for(int j = ; j < tot; j++) {
if(i * prime[j] > N) {
break;
}
check[i * prime[j]] = true;
if(i % prime[j] == ) {
mu[i * prime[j]] = ;
break;
} else {
mu[i * prime[j]] = -mu[i];
}
}
}
} int main()
{
#ifdef local
freopen("data.txt", "r", stdin);
// freopen("data.txt", "w", stdout);
#endif
Moblus();
int t;
scanf("%d",&t);
while(t--) {
ll n;
scanf("%lld",&n);
ll ans = ;
for(int i = ; i <= ; i++) {
if(!mu[i]) continue;
ll raiz = round(pow(n, 1.0 / i));
while(pow((long double)raiz, i) > (long double)n) raiz--;
while(pow((long double)raiz + , i) <= (long double)n) raiz++;
raiz--;
ans += (ll)mu[i] * raiz;
}
printf("%lld\n",n - + ans);
}
return ;
}

Educational Codeforces Round 50 (Rated for Div. 2) F - Relatively Prime Powers(数学+容斥)的更多相关文章

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

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

  2. Codeforces Educational Codeforces Round 44 (Rated for Div. 2) F. Isomorphic Strings

    Codeforces Educational Codeforces Round 44 (Rated for Div. 2) F. Isomorphic Strings 题目连接: http://cod ...

  3. Educational Codeforces Round 71 (Rated for Div. 2)-F. Remainder Problem-技巧分块

    Educational Codeforces Round 71 (Rated for Div. 2)-F. Remainder Problem-技巧分块 [Problem Description] ​ ...

  4. Educational Codeforces Round 50 (Rated for Div. 2) C. Classy Numbers

    C. Classy Numbers 题目链接:https://codeforces.com/contest/1036/problem/C 题意: 给出n个询问,每个询问给出Li,Ri,问在这个闭区间中 ...

  5. Educational Codeforces Round 50 (Rated for Div. 2)的A、B、C三题AC代码

    A题链接:https://codeforces.com/contest/1036/problem/A A题AC代码: #include <stdio.h> #include <std ...

  6. Educational Codeforces Round 50 (Rated for Div. 2) E. Covered Points

    注释上都有解析了,就不写了吧,去重的问题就用set解决,并且呢第i个线段最多和其他线段产生i-1个交点,n^2logn. #include <cmath> #include <cst ...

  7. Educational Codeforces Round 58 (Rated for Div. 2) F dp + 优化(新坑) + 离线处理

    https://codeforces.com/contest/1101/problem/F 题意 有n个城市,m辆卡车,每辆卡车有起点\(s_i\),终点\(f_i\),每公里油耗\(c_i\),可加 ...

  8. Educational Codeforces Round 42 (Rated for Div. 2)F - Simple Cycles Edges

    http://codeforces.com/contest/962/problem/F 求没有被两个及以上的简单环包含的边 解法:双联通求割顶,在bcc中看这是不是一个简单环,是的话把整个bcc的环加 ...

  9. Educational Codeforces Round 90 (Rated for Div. 2) A. Donut Shops(数学)

    题目链接:https://codeforces.com/contest/1373/problem/A 题意 有两种包装的甜甜圈,第一种 $1$ 个 $a$ 元,第二种 $b$ 个 $c$ 元,问买多少 ...

随机推荐

  1. 日常工作问题解决:记一次centos7上的lvm表错误解决过程

    问题描述: 公司大数据hadoop2服务器采用电信云服务器,后来故障,电信恢复该服务器,需要重新部署程序,需要扩展lvm分区,但是使用pvsan命令发现有报错信息,需要解决以防重启后,因挂载问题,无法 ...

  2. RxJava基本使用

    更多文章请点击链接:http://77blogs.com/?p=162 转载请标明出处:https://www.cnblogs.com/tangZH/p/12088300.html,http://77 ...

  3. 如何获得select被选中option的value和text和......

    我想获取select选中的value,或者text,或者…… 比如这个: <select id="select"> <option value="A&q ...

  4. 记录一次 hadoop yarn resourceManager无故切换的故障

    某日 收到告警 线上集群rm切换 观察resourcemanager 日志报错如下 这行不明显 再看看其他日志报错 在 app attempt_removed 时候发生了空指针错误 break; ca ...

  5. Java 关于String Pool

    下面的文章讲得挺清楚: https://www.baeldung.com/java-string-pool 再加一个关于虚拟机的,因为上面的文章提到了JVM: https://abhirockzz.w ...

  6. Oracle 分页语句

    ** 写法1 :采用 ROWNUM的伪列: --查询10到20之间的数据 -- SELECT * FORM ( -- SELECT * , ROWNUM rn FROM TABLE_NAME -- W ...

  7. js之数据类型(对象类型——构造器对象——正则)

    正则(regular expression)描述了一种字符串的匹配式.一般应用在一些方法中,用一些特殊的符号去代表一些特定的内容,对字符串中的信息实现查找,替换,和提取的操作.js中的正则表达式用Re ...

  8. linux 最常用命令

    1.创建文件.文件夹 touch 文件名 mkdir 文件夹 2.文件赋权 filename 3.查看文件大小 work/testing ll -h .查找文件 find / -name 'filen ...

  9. 【转】SpringBoot+SpringCloud实现登录用户信息在微服务之间的传递

    实现思路: 1:准备一个ThreadLocal变量,供线程之间共享. 2:每个微服务对所有过来的Feign调用进行过滤,然后从请求头中获取User用户信息,并存在ThreadLocal变量中. 3:每 ...

  10. SpringBoot之Redis访问(spring-boot-starter-data-redis)

    依赖注入: <!--dependency for redis--> <!-- https://mvnrepository.com/artifact/org.springframewo ...