Educational Codeforces Round 50 (Rated for Div. 2)F. Relatively Prime Powers
实际上就是求在[2,n]中,x != a^b的个数,那么实际上就是要求x=a^b的个数,然后用总数减掉就好了。
直接开方求和显然会有重复的数。容斥搞一下,但实际上是要用到莫比乌斯函数的,另外要注意减掉1^b这种情况。
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cassert>
#include <cstring>
#include <set>
#include <map>
#include <list>
#include <queue>
#include <string>
#include <iostream>
#include <algorithm>
#include <functional>
#include <stack>
using namespace std;
typedef long long ll;
#define T int t_;Read(t_);while(t_--)
#define dight(chr) (chr>='0'&&chr<='9')
#define alpha(chr) (chr>='a'&&chr<='z')
#define INF (0x3f3f3f3f)
#define maxn (300005)
#define maxm (10005)
#define mod 1000000007
#define ull unsigned long long
#define repne(x,y,i) for(i=(x);i<(y);++i)
#define repe(x,y,i) for(i=(x);i<=(y);++i)
#define repde(x,y,i) for(i=(x);i>=(y);--i)
#define repdne(x,y,i) for(i=(x);i>(y);--i)
#define ri register int
inline void Read(int &n){char chr=getchar(),sign=;for(;!dight(chr);chr=getchar())if(chr=='-')sign=-;
for(n=;dight(chr);chr=getchar())n=n*+chr-'';n*=sign;}
inline void Read(ll &n){char chr=getchar(),sign=;for(;!dight(chr);chr=getchar())if
(chr=='-')sign=-;
for(n=;dight(chr);chr=getchar())n=n*+chr-'';n*=sign;}
int mu[],prim[],len;
ll n;
bool isprim[];
void init(){
for(int i = ;i <= ;++i) isprim[i] = true;
for(int i = ;i <= ;++i){
if(isprim[i]) prim[len++] = i,mu[i] = -;
for(int j = ;j < len && i * prim[j] <= ;++j){
mu[i*prim[j]] = -mu[i];
isprim[i*prim[j]] = false;
if(i % prim[j] == ){
mu[i*prim[j]] = ;
break;
}
}
}
}
int main()
{
freopen("a.in","r",stdin);
freopen("b.out","w",stdout);
init();
T{
Read(n);
ll sum = ;
for(int i = ;i <= ;++i){
sum = sum + (ll)mu[i] * ((ll)pow((long double)n+0.1,(long double)1.0/i)-);//减掉等于1的情况
}
printf("%lld\n",sum+n-);
}
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(数学+容斥)
题目链接:http://codeforces.com/contest/1036/problem/F 题意: 题解:求在[2,n]中,x != a ^ b(b >= 2 即为gcd)的个数,那么实 ...
- 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 41 (Rated for Div. 2)F. k-substrings
题意比较麻烦略 题解:枚举前缀的中点,二分最远能扩展的地方,lcp来check,然后线段树维护每个点最远被覆盖的地方,然后查询线段树即可 //#pragma GCC optimize(2) //#pr ...
随机推荐
- git设置log的别名 for hist
hist -- alias for 'log --color --graph --date=short --pretty=format:'%Cred%h%Creset -%C(yellow)%d%C ...
- HTTP 方法:GET 对比 POST 转自w3school
两种最常用的 HTTP 方法是:GET 和 POST. 什么是 HTTP? 超文本传输协议(HTTP)的设计目的是保证客户机与服务器之间的通信. HTTP 的工作方式是客户机与服务器之间的请求-应答协 ...
- jmeter的JVM参数设置
JMeter用户可根据运行的计算机配置,来适当调整JMeter.bat中的JVM调优设置,如下所示: set HEAP=-Xms512m -Xmx512m set NEW=-XX:NewSize=12 ...
- docker 镜像仓库的安装与使用
安装Docker Compose 解决依赖 [root@service-1 ~]# curl -L "https://github.com/docker/compose/releases/d ...
- docker 应用数据的管理之bind mounts
创建容器使用bind mounts 挂载文件系统.宿主机文件系统会覆盖掉容器里初始数据 [root@localhost ~]# mkdir /www/htpm -pv mkdir: 已创建目录 &qu ...
- centos下安装nodejs的三种种方式
方法一:源码包安装 官网下载 centos下载最新版10.9 https://nodejs.org/dist/v10.9.0/node-v10.9.0-linux-x64.tar.xz mkdir / ...
- Java数据结构和算法(一)--栈
栈: 英文名stack,特点是只允许访问最后插入的那个元素,也就是LIFO(后进先出) jdk中的stack源码: public class Stack<E> extends Vector ...
- Sql Server 中锁的概念(1)
Sql Server 中锁的概念 锁的概述 一. 为什么要引入锁 多个用户同时对数据库的并发操作时会带来以下数据不一致的问题: 丢失更新A,B两个用户读同一数据并进行修改,其中一个用户的修改结果破 ...
- SQL Server查看表的约束
sysobjects是系统自建的表,里面存储了在数据库内创建的每个对象,包括约束.默认值.日志.规则.存储过程等. SELECT * FROM sysobjects WHERE OBJECT_NAME ...
- [LOJ] 分块九题 2
https://loj.ac/problem/6278 区间修改,查询区间第k大. 块内有序(另存),块内二分. 还是用vector吧,数组拷贝排序,下标搞不来.. //Stay foolish,st ...