Codeforces1036F Relatively Prime Powers 【容斥原理】
题目分析:
这种题目标题写莫比乌斯反演会不会显得太恐怖了,那就容斥算了。
gcd不为1的肯定可以开根。所以把根式结果算出来就行了。
辣鸡题目卡我精度。
代码:
#include<bits/stdc++.h>
using namespace std; const long long LMAX = ; long long n;
int mu[]; void init(){
for(int i=;i<=;i++){
int p = i;
mu[i] = -;
for(int j=;j*j<=p;j++){
int cnt = ; while(p%j == ) p/=j,cnt++;
if(cnt != && cnt != ) mu[i] = ;
else if(cnt == ) mu[i]*=-;
}
if(p != ) mu[i]*=-;
}
} long long fast_pow(int now,int pw){
long long ans = ,dt = now;
int bit = ;
while(bit <= pw){
if(bit & pw){
if(ans < LMAX/dt) ans *= dt;
else ans = LMAX;
}
if(dt < LMAX/dt) dt *= dt;
else dt = LMAX;
bit<<=;
}
return ans;
} void work(){
long long ans = ;
for(int i=;i<=;i++){
if(mu[i] == ) continue;
int z = pow((long double)n,1.0/(long double)i);
if(z == ) break;
if(fast_pow(z,i) > n) z--;
if(fast_pow(z+,i) <= n) z++;
z--; ans += z*mu[i];
}
n -= ans;n--;
printf("%I64d\n",n);
} int main(){
int Tmp; scanf("%d",&Tmp);
init();
while(Tmp--){
scanf("%I64d",&n);
work();
}
return ;
}
Codeforces1036F Relatively Prime Powers 【容斥原理】的更多相关文章
- Relatively Prime Powers CodeForces - 1036F (莫比乌斯函数容斥)
Relatively Prime Powers CodeForces - 1036F Consider some positive integer xx. Its prime factorizatio ...
- F. Relatively Prime Powers (求([2,n],内不是次方的数量)
题目:经过提炼后, 题目的意思就是问[2,n] 内,不是次方数的数量 ,: 思路: 答案就是 原理是利用容斥,注意n开i次根是向下取整(这题巨卡精度) 这是大神的思路 ,, 我还没有理解, 先放着,等 ...
- 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)的个数,那么实 ...
- Educational Codeforces Round 50 (Rated for Div. 2)F. Relatively Prime Powers
实际上就是求在[2,n]中,x != a^b的个数,那么实际上就是要求x=a^b的个数,然后用总数减掉就好了. 直接开方求和显然会有重复的数.容斥搞一下,但实际上是要用到莫比乌斯函数的,另外要注意减掉 ...
- 容斥原理 求M以内有多少个跟N是互质的
开始系统的学习容斥原理!通常我们求1-n中与n互质的数的个数都是用欧拉函数! 但如果n比较大或者是求1-m中与n互质的数的个数等等问题,要想时间效率高的话还是用容斥原理! 本题是求[a,b]中与n ...
- Educational Codeforces Round 50
1036A - Function Height 20180907 \(ans=\left \lceil \frac{k}{n} \right \rceil\) #include<bits/ ...
- 【线性筛】【筛法求素数】【素数判定】URAL - 2102 - Michael and Cryptography
暴力搞肯定不行,因此我们从小到大枚举素数,用n去试除,每次除尽,如果已经超过20,肯定是no.如果当前枚举到的素数的(20-已经找到的质因子个数)次方>剩下的n,肯定也是no.再加一个关键的优化 ...
- Ural2102:Michael and Cryptography(数论&素数)
The hacker Michael develops breakthrough password manager, which is called KEK (Keeper of Encrypted ...
- hdu4059 The Boss on Mars(差分+容斥原理)
题意: 求小于n (1 ≤ n ≤ 10^8)的数中,与n互质的数的四次方和. 知识点: 差分: 一阶差分: 设 则 为一阶差分. 二阶差分: n阶差分: 且可推出 性质: 1. ...
随机推荐
- 解决win7 win10上网卡慢问题
在管理员身份运行CMD命令行,然后输入netsh interface tcp set global autotuninglevel=disable 即可.
- A short Glimpse to Spectral Sequences 快速入坑谱序列(英文)
In this short paper with a few of page (but a lot of language mistake), I want to introduce the theo ...
- Python遇到问题总结
1.list的集合 循环删除一个list数据时,会遇到一丢丢问题,详情看Python的list循环遍历中,删除数据的正确方法 但是,里面说的要反转一下list集合,可以用a[::-1]这种方法. &g ...
- H5 55-行高
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- Pytorch 初识
文章目录 一个简单的回归网络的例子 再来一个例子 官方教程上图片识别的例子 import torch import torch.nn as nn import torch.nn.functional ...
- 在Git中添加一个项目
首先保证Git服务器正确配置,管理员机器可正常连接并使用Git. 第一步:在服务器上新建一个项目仓库 切换到git用户: a@ubuntu:/home/git$ su - git $ cd /home ...
- scrapy之五大核心组件
scrapy之五大核心组件 scrapy一共有五大核心组件,分别为引擎.下载器.调度器.spider(爬虫文件).管道. 爬虫文件的作用: a. 解析数据 b. 发请求 调度器: a. 队列 队列是一 ...
- [2017BUAA软工助教]案例分析小结
BUAA案例分析小结 一.作业要求 http://www.cnblogs.com/jiel/p/7631784.html 二.统计数据 总人数 神策数据 博客园博客 必应词典 30 1 12 17 三 ...
- 【学习总结】Git学习-参考廖雪峰老师教程九-使用码云
学习总结之Git学习-总 目录: 一.Git简介 二.安装Git 三.创建版本库 四.时光机穿梭 五.远程仓库 六.分支管理 七.标签管理 八.使用GitHub 九.使用码云 十.自定义Git 期末总 ...
- Linux系统中常用的命令汇总
日常开发,上线的服务器系统一般都是Linux系统,所以,熟练的掌握常用的命令操作就尤其的重要了 1) 查看某个服务的运行情况 (例如Redis) ps -ef | grep redis //e-显示程 ...