【XSY1580】Y队列 容斥
题目大意
给你\(n,r\),求第\(n\)个不能被表示为\(a^b(2\leq b\leq r)\)的数
\(n\leq 2\times {10}^{18},r\leq 62\)
题解
我们考虑二分,求\(\leq m\)的不能被表示为\(a^b\)的数\(f(m)\)
我们先忽略\(1\)
我们钦定能被表示为\(a^2,a^3,a^5\)等\(b\)为质数的数,贡献为\(\lfloor\sqrt[2]{m}\rfloor-1,\lfloor\sqrt[3]{m}\rfloor-1\cdots\),这样也会包含当\(b\)为合数时的情况,例如\(a^4={(a^2)}^2\)
但我们算多了,例如\(a^3=b^2=c^6\),所以我们要减掉\(b\)为两个不同的质数的积的情况,即\(\lfloor\sqrt[6]{m}\rfloor-1,\lfloor\sqrt[10]{m}-1\rfloor\cdots\)
然后加上\(b\)为三个不同的质数的积的情况,减掉\(b\)为四个不同的质数的积的情况……
我们发现\(b=x\)时容斥系数为\(\mu(x)\)
当\(b>62\)时\(\lfloor\sqrt[b]{m}\rfloor=1\),所以不用继续往下算了
还有,开\(n\)次根号可以用pow,不过要传long double参数进去,不然就会炸精度。
但是这样子还会tle,因为有\(30000\)组数据
我们发现\(f(x)\approx\sqrt{x}\)
我们计算出\(f(n)\),然后每次把\(n\)加上\(n-f(n)\),可以很快得到答案
时间复杂度:\(O(???)\)
反正能过且常数巨大就对了
代码
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cstdlib>
#include<ctime>
#include<utility>
#include<cmath>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef long double ld;
int p[100];
int u[100];
int b[100];
int mx[100];
int cnt;
ll n;
int k;
ll fp(ll a,ll b)
{
ll s=1;
while(b)
{
if(b&1)
s=s*a;
a=a*a;
b>>=1;
}
return s;
}
ll calc(ll n,ll x)
{
ll s=floor(ld(pow(ld(n),ld(1)/x)));
return s;
}
ll count(ll x)
{
int i;
ll s=0;
ll nw;
for(i=1;i<=62;i++)
if(mx[i]<=k&&u[i])
{
nw=calc(x,i)-1;
if(!nw)
break;
s+=u[i]*nw;
}
return s;
}
void solve()
{
scanf("%lld%d",&n,&k);
ll t=n;
ll s=count(t);
while(1)
{
t+=n-s;
s=count(t);
if(s==n)
break;
}
printf("%lld\n",t);
}
int main()
{
int i,j;
cnt=0;
memset(b,0,sizeof b);
u[1]=1;
mx[1]=1;
for(i=2;i<=62;i++)
{
if(!b[i])
{
p[++cnt]=i;
mx[i]=i;
u[i]=-1;
}
for(j=1;j<=cnt&&i*p[j]<=62;j++)
{
b[i*p[j]]=1;
mx[i*p[j]]=mx[i];
if(i%p[j]==0)
{
u[i*p[j]]=0;
break;
}
u[i*p[j]]=-u[i];
}
}
int t;
scanf("%d",&t);
while(t--)
solve();
return 0;
}
【XSY1580】Y队列 容斥的更多相关文章
- HDU 5297 Y sequence 容斥 迭代
Y sequence 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5297 Description Yellowstar likes integer ...
- HDU2841 (队列容斥)
Visible TreesTime Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Tot ...
- Educational Codeforces Round 37 G. List Of Integers (二分,容斥定律,数论)
G. List Of Integers time limit per test 5 seconds memory limit per test 256 megabytes input standard ...
- HDU - 5297:Y sequence (迭代&容斥)
Yellowstar likes integers so much that he listed all positive integers in ascending order,but he hat ...
- Trees in a Wood. UVA 10214 欧拉函数或者容斥定理 给定a,b求 |x|<=a, |y|<=b这个范围内的所有整点不包括原点都种一棵树。求出你站在原点向四周看到的树的数量/总的树的数量的值。
/** 题目:Trees in a Wood. UVA 10214 链接:https://vjudge.net/problem/UVA-10214 题意:给定a,b求 |x|<=a, |y|&l ...
- hdu 5664 Lady CA and the graph(树的点分治+容斥)
题意: 给你一个有n个点的树,给定根,叫你找第k大的特殊链 .特殊的链的定义:u,v之间的路径,经过题给的根节点. 题解:(来自BC官方题解) 对于求第k大的问题,我们可以通过在外层套一个二分,将其转 ...
- HDU 4059 容斥初步练习
#include <iostream> #include <cstring> #include <cstdio> #include <algorithm> ...
- 【BZOJ-4455】小星星 容斥 + 树形DP
4455: [Zjoi2016]小星星 Time Limit: 10 Sec Memory Limit: 512 MBSubmit: 204 Solved: 137[Submit][Status] ...
- UVa12633 Super Rooks on Chessboard(容斥 + FFT)
题目 Source http://acm.hust.edu.cn/vjudge/problem/42145 Description Let’s assume there is a new chess ...
随机推荐
- python二:数据类型举例练习--小白博客
一.#字符串 res = 'hello,world' 1.#字符串切片取值:******* print(res[0:5]) 顾头不顾尾,取下标0-4的字符 print(res[0:-1:2]) 步长为 ...
- Mike and palindrome CodeForces - 798A
题目链接 一个简单的题目,但是却很少有人可以一次AC,比如我就瞎写wa了一次... 写本博算个教训录吧. 题目给出一个字符串,让你严格的改变一个字符使改变后的字符串是一个回文串. 回文串不用解释了.不 ...
- echarts各个配置项详细说明总结
https://blog.csdn.net/sinat_34492035/article/details/70258557 https://blog.csdn.net/qq_34908167/arti ...
- p76泛函 有限维空间真子空间不可能在全空间稠密
连续函数 然后多项式函数是稠密的 多项式子空间是无穷维的 多项式空间就是在全体连续函数的线性空间中稠密 有限维子空间是闭的 多项式空间也不是有限维 2的地方说 有限维真子空间必不稠密 那是对的啊 有 ...
- Python_函数的有用信息、带参数的装饰器、多个装饰器装饰一个函数
函数的有用信息 代码1: def login(username, password): """ 此函数需要用户名,密码两个参数,完成的是登录的功能. :return: T ...
- vue动态class——实现tag的选中状态
vue动态class——实现tag的选中状态 <template> <div class="common-nav"> <div class=" ...
- HTML,CSS笔记
text-indent 属性规定文本块中首行文本的缩进.允许使用负值.如果使用负值,那么首行会被缩进到左边.p{ text-indent:50px; } HTML <label> 标签的 ...
- Failure to transfer org.apache.maven:maven-archiver:pom:2.5 from https://repo.maven.apache.org/maven2 was cached in the local repository, resolution will not be reattempted until the update interval o
pom.xml报错: Failure to transfer org.apache.maven:maven-archiver:pom:2.5 from https://repo.maven.apach ...
- java依赖的斗争:依赖倒置、控制反转和依赖注入
控制反转(Inversion Of Controller)的一个著名的同义原则是由Robert C.Martin提出的依赖倒置原则(Dependency Inversion Principle),它的 ...
- Java Integer 与 int 深刻理解
今天在做Object 自动转为Integer 类型之后的判断,遇到一个不理解的点,当数值超过127之后,两个数值相同的Object 对象用 == 判断的结果是false. Object a = 128 ...