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. ...
随机推荐
- 【Python】动手分析天猫内衣售卖数据,得到你想知道的信息
大家好,希望各位能怀着正直.严谨.专业的心态观看这篇文章.ヾ(๑╹◡╹)ノ" 接下来我们尝试用 Python 抓取天猫内衣销售数据,并分析得到中国女性普遍的罩杯数据.最受欢迎的内衣颜色是什么 ...
- 一文看懂Transformer内部原理(含PyTorch实现)
Transformer注解及PyTorch实现 原文:http://nlp.seas.harvard.edu/2018/04/03/attention.html 作者:Alexander Rush 转 ...
- python 获取lazada菲律宾站地址库
import urllib3 import requests import ast import time # 因为lazada返回的数据是json类型,通过解码成字符串类型,为了方便数据操作,使用字 ...
- python3 pip 安装Scrapy在win10 安装报错error: Microsoft Visual C++ 14.0 is required. Get it with "Microsoft Visual C++ Build Tools": http://landinghub.visualstudio.com/visual-cpp-build-tools
问题描述 当前环境win10,python_3.6.1,64位. 在windows下,在dos中运行pip install Scrapy报错: building 'twisted.test.raise ...
- B-Tree 和 B+Tree
B-Tree和B+Tree 本文来自 Hubery_James 的CSDN 博客 ,全文地址请点击:原文地址-干货满满 B+树索引是B+树在数据库中的一种实现,是最常见也是数据库中使用最为频繁的一种索 ...
- ElasticSearch(简称ES)
Windows下安装ElasticSearch ElasticSearch(简称ES)是一个基于Lucene的分布式全文搜索服务器,和SQL Server的全文索引(Fulltext Index) ...
- Linux下用rm删除的文件的恢复方法
Linux下用rm删除的文件的恢复方法_Linux教程_Linux公社-Linux系统门户网站https://www.linuxidc.com/Linux/2008-08/14744.htm linu ...
- Python3练习题 026:求100以内的素数
p = [i for i in range(2,100)] #建立2-99的列表 for i in range(3,100): #1和2都不用判断,从3开始 for j in range(2, ...
- [转帖]HTTP 头部解释
HTTP 头部解释 https://www.cnblogs.com/poissonnotes/p/4844014.html 之前看的太粗了 同事闻起来 referer 才知道自己所知甚少.. ==== ...
- vue页面是否缓存的两种方式
第一种 <keep-alive> <router-view v-if="$route.meta.keepAlive"></router-view> ...