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. ...
随机推荐
- Jvm 参数笔记
Jvm参数含义 https://cloud.tencent.com/developer/article/1129474 从一道题说起 https://blog.csdn.net/crazylzxlzx ...
- flask请求流程详解
先看一个流程图: 1.当一个请求进入的时候,Flask框架首先会实例化一个Request Context,封装了请求信息,保存在Request中.生成请求上下文后,Flask框架会将请求上下文推入到_ ...
- java 抽象
MotoVehicle抽象类 package text1; /* * 抽象 */ public abstract class MotoVehicle { // 共同的属性 private String ...
- JS 有趣的JS
一. var arr = []; for (var i = 0; i < 3; i++) { arr[i] = function() { console.log(i+'__') // 3 3 3 ...
- UnderWater+SDN论文之四
Open Source Suites for Underwater Networking:WOSS and DESERT Underwater Source: IEEE Network, 2014 仿 ...
- SoftWater——SDN+UnderWater系列论文一
---- SoftWater: Software-defined networking for next-generation underwater communication systems 来源: ...
- VO和DO转换(三) Dozer
VO和DO转换(一) 工具汇总 VO和DO转换(二) BeanUtils VO和DO转换(三) Dozer VO和DO转换(四) MapStruct 可参考的资料: dozer官网 Dozer(Jav ...
- Jenkins [Error] at org.codehaus.cargo.container.tomcat.internal.AbstractTomcatManagerDeployer.redeploy(AbstractTomcatManagerDeployer.java:192)
Deploying /root/.jenkins/workspace/zgg-crm-pre/target/crm.war to container Tomcat 7.x Remote with co ...
- [转帖]firewall-cmd
firewall-cmd https://wangchujiang.com/linux-command/c/firewall-cmd.html 高手大作 等哪天需要防火墙了 再练习一下. Linux上 ...
- 使用npm安装一些包失败了,更换npm源
镜像使用方法(三种办法任意一种都能解决问题,建议使用第三种,将配置写死,下次用的时候配置还在): 1.通过config命令 npm config set registry https://regist ...