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)的个数,那么实际上就是要求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(数学+容斥)的更多相关文章
- Educational Codeforces Round 50 (Rated for Div. 2)F. Relatively Prime Powers
实际上就是求在[2,n]中,x != a^b的个数,那么实际上就是要求x=a^b的个数,然后用总数减掉就好了. 直接开方求和显然会有重复的数.容斥搞一下,但实际上是要用到莫比乌斯函数的,另外要注意减掉 ...
- 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 ...
- Educational Codeforces Round 71 (Rated for Div. 2)-F. Remainder Problem-技巧分块
Educational Codeforces Round 71 (Rated for Div. 2)-F. Remainder Problem-技巧分块 [Problem Description] ...
- Educational Codeforces Round 50 (Rated for Div. 2) C. Classy Numbers
C. Classy Numbers 题目链接:https://codeforces.com/contest/1036/problem/C 题意: 给出n个询问,每个询问给出Li,Ri,问在这个闭区间中 ...
- 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 ...
- Educational Codeforces Round 50 (Rated for Div. 2) E. Covered Points
注释上都有解析了,就不写了吧,去重的问题就用set解决,并且呢第i个线段最多和其他线段产生i-1个交点,n^2logn. #include <cmath> #include <cst ...
- 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\),可加 ...
- Educational Codeforces Round 42 (Rated for Div. 2)F - Simple Cycles Edges
http://codeforces.com/contest/962/problem/F 求没有被两个及以上的简单环包含的边 解法:双联通求割顶,在bcc中看这是不是一个简单环,是的话把整个bcc的环加 ...
- Educational Codeforces Round 90 (Rated for Div. 2) A. Donut Shops(数学)
题目链接:https://codeforces.com/contest/1373/problem/A 题意 有两种包装的甜甜圈,第一种 $1$ 个 $a$ 元,第二种 $b$ 个 $c$ 元,问买多少 ...
随机推荐
- 创建安全的 Netty 程序
1.使用 SSL/TLS 创建安全的 Netty 程序 SSL 和 TLS 是众所周知的标准和分层的协议,它们可以确保数据时私有的 Netty提供了SSLHandler对网络数据进行加密 使用Http ...
- selenium登录实验楼
from selenium import webdriver from selenium.webdriver.common.by import By from selenium.webdriver.s ...
- Java打包
打成jar包 如果你使用的是maven来管理项目,执行以下命令既可以 cd 项目跟目录(和pom.xml同级)mvn clean package## 或者执行下面的命令## 排除测试代码后进行打包mv ...
- 【思维】ABC
题目描述 You are given a string s consisting of A, B and C.Snuke wants to perform the following operatio ...
- 监控 Kubernetes 集群应用
Prometheus的数据指标是通过一个公开的 HTTP(S) 数据接口获取到的,我们不需要单独安装监控的 agent,只需要暴露一个 metrics 接口,Prometheus 就会定期去拉取数据: ...
- HTTP协议探究(序章)
1 HTTP协议基于TCP协议 (1)TCP三次握手连接 HTTP客户端(Chrome浏览器): IP:192.168.1.47 端口:59875 MSS:1460 HTTP服务器(Nginx服务器) ...
- Unity Button延迟功能
有时候Button点下去不是要求立即反应的,而是先有个特别短的动画,再反应. 实现: 继承Button,然后重写一下OnPointerClick,利用协程来延迟. using System.Colle ...
- Git FLS的使用
克隆git地址后,一些文件内容被隐藏. 显示如下: version https://git-lfs.github.com/spec/v1oid sha256:xxxxxxxxxxxxxxxxxxxxx ...
- 关于微信小程序返回页面时刷新页面的实现
在小程序开发中,我们通常会遇到这样的需求:提交某个表单成功后跳转该表单详情页面,但是返回时需要跳转回到首页(注意:我这里的首页是提交表单页的前一个页面),而不能再返回提交表单的页面,并且要在首页中刷新 ...
- windows 10 mysql-8.0.17-winx64的安装
1.官网下载,并解压 https://dev.mysql.com/downloads/mysql/ 下载下来之后是一个zip的压缩包文件:mysql-5.7.26-winx64.zip,然后对这个文件 ...