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 ...
随机推荐
- java中properties的使用实例
package com.ywx.io; import java.io.File; import java.io.FileInputStream; import java.io.FileOutputSt ...
- How `new’ operator works ?
这是2013年写的一篇旧文,放在gegahost.net上面 http://raison.gegahost.net/?p=15 February 15, 2013 How `new’ operator ...
- hdu 5402 Travelling Salesman Problem (技巧,未写完)
题意:给一个n*m的矩阵,每个格子中有一个数字,每个格子仅可以走一次,问从(1,1)走到(n,m) 的路径点权之和. 思路: 想了挺久,就是有个问题不能短时间证明,所以不敢下手. 显然只要n和m其中一 ...
- js 字符串截取 substring() 方法、 substr() 方法、slice() 方法、split() 、join();
三种 js 截取字符串的方法: substring() 方法: substr() 方法: slice() 方法: 1.:substring() 方法:string.substring(from, to ...
- dropdb - 删除一个现有 PostgreSQL 数据库
SYNOPSIS dropdb [ option...] dbname DESCRIPTION 描述 dropdb 删除一个现有 PostgreSQL 数据库. 执行这条命令的人必须是数据库超级用户, ...
- tomcat 虚拟目录配置
1.虚拟目录优点 原始 拷贝到webapps下,然后启动tomcat,就可以访问webapps下的项目.eclipse配置tomcat的原理也是这种方式. 虚拟目录 定位到eclipse工作目录下,实 ...
- 下拉列表事件 Dropdown iview
<Dropdown @on-click="export"> <Button icon='md-log-out'> 000l <Icon type=&q ...
- // mounted: {}, 原来是 空方法 导致了 vue 的警告 !| [Vue warn]: Error in mounted hook: "TypeError: handlers[i].call is not a function"
// mounted: {}, 原来是 空方法 导致了 vue 的警告 !| vue.runtime.esm.js?2b0e:587 [Vue warn]: Error in mounted hook ...
- Python基础4 迭代器,生成器,装饰器,Json和pickle 数据序列化
本节内容 迭代器&生成器 装饰器 Json & pickle 数据序列化 软件目录结构规范 作业:ATM项目开发 1.列表生成式,迭代器&生成器 列表生成式 孩子,我现在有个需 ...
- 1-jdk的安装与配置
1- Jvm.jdk.jre之间的关系 JVM:Java虚拟机,保证java程序跨平台.(Java Virtual Machine) JRE: Java运行环境,包含JVM和核心类库.如果只是想运行j ...