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. ...
随机推荐
- Item 22: 当使用Pimpl机制时,在实现文件中给出特殊成员函数的实现
本文翻译自<effective modern C++>,由于水平有限,故无法保证翻译完全正确,欢迎指出错误.谢谢! 博客已经迁移到这里啦 如果你曾经同过久的编译时间斗争过,那么你肯定对Pi ...
- 07 YAPI/基础设施 - DevOps之路
07 YAPI/基础设施 - DevOps之路 文章Github地址,欢迎start:https://github.com/li-keli/DevOps-WiKi 简介 YApi 是一个可本地部署的. ...
- 接口自动化框架(Pytest+request+Allure)
前言: 接口自动化是指模拟程序接口层面的自动化,由于接口不易变更,维护成本更小,所以深受各大公司的喜爱. 接口自动化包含2个部分,功能性的接口自动化测试和并发接口自动化测试. 本次文章着重介绍第一种, ...
- RestTemplete
RestTemplete是由spring提供的,可以用来模拟浏览器进行服务调用的封装好的Api,和Apache 的HttpClient功能相同,在分布式系统中可以用来服务之间的调用. 开发步骤: 1. ...
- shell脚本--CGI获取请求数据(GET / POST)
Case 1: 获取地址栏传递的参数(即通过GET方式) CGI的环境变量中有个QUERY_STRING,可以获取地址栏传递的参数,该参数可以是手动加上的,也可以是通过表单的get方式提交的,比如下面 ...
- Hive简单编程实践-词频统计
一.使用MapReduce的方式进行词频统计 (1)在HDFS用户目录下创建input文件夹 hdfs dfs -mkdir input 注意:林子雨老师的博客(http://dblab.xmu.ed ...
- 解决selenium.common.exceptions.WebDriverException: Message: 'chromedriver' executable needs to be in PATH. Please see https://sites.google.com/a/chromium.org/chromedriver/home
解决方案: 1.查看浏览器当前版本:chrome://version/. 2.到https://sites.google.com/a/chromium.org/chromedriver/downloa ...
- CodeForces Round #529 Div.3
http://codeforces.com/contest/1095 A. Repeating Cipher #include <bits/stdc++.h> using namespac ...
- MySQL的binlog及关闭方法
如何关闭MySQL日志,删除mysql-bin.0000*日志文件 - VPS侦探https://www.vpser.net/manage/delete-mysql-mysql-bin-0000-lo ...
- WPF中定时器Timer与DispatcherTimer的用法
最近的工作项目中需要定时更新UI控件中的数据,这时候第一反应肯定会想到去使用System.Timers.Timer定时更新UI控件,但是程序运行后,会发现程序崩溃了.报的异常为“调用线程无法访问此对象 ...