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$ 元,问买多少 ...
随机推荐
- 论文翻译:Conditional Random Fields as Recurrent Neural Networks
Conditional Random Fields as Recurrent Neural Networks ICCV2015 cite237 1摘要: 像素级标注的重要性(语义分割 图像理解) ...
- java微信token校验
1.微信验证接口 package com.park.utils.wechatUtil; import org.springframework.web.bind.annotation.RequestMa ...
- [DEBUG] java中用Runtime调用python 简单程序输出null
今天需要在java中调用python脚本,首先考虑的是java自带的Runtime 在ubuntu和win10下分别测试,发现win10报错 java源代码 @Test public void tes ...
- 剑指offer24:二叉树中和为输入整数值的所有路径。(注意: 在返回值的list中,数组长度大的数组靠前)
1 题目描述 输入一颗二叉树的根节点和一个整数,打印出二叉树中结点值的和为输入整数的所有路径.路径定义为从树的根结点开始往下一直到叶结点所经过的结点形成一条路径.(注意: 在返回值的list中,数组长 ...
- S02_CH14_ EMIO_OLED 实验
S02_CH14_ EMIO_OLED 实验 本章将使用EMIO模拟OLED的时序来驱动OLED,本方案对米联系列Miz702,Miz702N和Miz701N全兼容. 14.1板载OLED硬件原理 M ...
- Skywalking的增强与拦截机制
整理自架构经理(汤哥)的分享 字节增强条件匹配 在 skywalking 中实现很多基于 byte-buddy 的关于链式匹配查询的实现, 代码如下所示: public abstract class ...
- ie/chorme 清除缓存 刷新js,css
1 有时候你发现你刚改过的js 没有用,然后就是你的浏览器 没有清楚缓存,它可能还是保存的之前的 网页文件: chorme 浏览器下(版本:ver 59.0.3071.104(正式版本) (64 位) ...
- 客户端相关知识学习(九)之h5给app传递数据
方法一: 情况一: if (window.JdAndroid){ window.JdAndroid.setPayCompleted(); window.JdAndr ...
- Pytorch入门随手记
Pytorch入门随手记 什么是Pytorch? Pytorch是Torch到Python上的移植(Torch原本是用Lua语言编写的) 是一个动态的过程,数据和图是一起建立的. tensor.dot ...
- 日志(logging)与正则(re)模块
logging模块 #日志:日常的流水 =>日志文件,将程序运行过程中的状态或数据进行记录,一般都是记录到日志文件中 #1.logging模块一共分为五个打印级别 debug.info.warn ...