题目大意

  给你\(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队列 容斥的更多相关文章

  1. HDU 5297 Y sequence 容斥 迭代

    Y sequence 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5297 Description Yellowstar likes integer ...

  2. HDU2841 (队列容斥)

    Visible TreesTime Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Tot ...

  3. 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 ...

  4. HDU - 5297:Y sequence (迭代&容斥)

    Yellowstar likes integers so much that he listed all positive integers in ascending order,but he hat ...

  5. 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 ...

  6. hdu 5664 Lady CA and the graph(树的点分治+容斥)

    题意: 给你一个有n个点的树,给定根,叫你找第k大的特殊链 .特殊的链的定义:u,v之间的路径,经过题给的根节点. 题解:(来自BC官方题解) 对于求第k大的问题,我们可以通过在外层套一个二分,将其转 ...

  7. HDU 4059 容斥初步练习

    #include <iostream> #include <cstring> #include <cstdio> #include <algorithm> ...

  8. 【BZOJ-4455】小星星 容斥 + 树形DP

    4455: [Zjoi2016]小星星 Time Limit: 10 Sec  Memory Limit: 512 MBSubmit: 204  Solved: 137[Submit][Status] ...

  9. UVa12633 Super Rooks on Chessboard(容斥 + FFT)

    题目 Source http://acm.hust.edu.cn/vjudge/problem/42145 Description Let’s assume there is a new chess ...

随机推荐

  1. *args **kwargs

    -----------耐得住寂寞,守得住芳华. # # -------------------------------[day10作业及默写]----------------------------- ...

  2. Truncated Power Method for Sparse Eigenvalue Problems

    目录 算法 k的选择 \(x\)的初始化 代码 抱歉,真的没怎么看懂,当然,估计和我现在没法静下心来好好看也有关系. 算法 想法非常非常简单吧,就是在原来幂法的基础上,每次迭代的时候再加个截断.当然, ...

  3. 448C - Painting Fence(分治)

    题意:给出宽为1高为Ai的木板n条,排成一排,每次上色只能是连续的横或竖并且宽度为1,问最少刷多少次可以使这些木板都上上色 分析:刷的第一步要么是所有的都竖着涂完,要么是先横着把最矮的涂完,如果是第一 ...

  4. stl stack用法

    栈后进先出 #include<iostream> #include<algorithm> #include<cstdio> #include<stack> ...

  5. Summer sell-off CodeForces - 810B (排序后贪心)

    Summer holidays! Someone is going on trips, someone is visiting grandparents, but someone is trying ...

  6. stark组件的增删改(新)

      1.效果图 2.详细步骤解析 3.总结.代码   1.效果图 增 删除 改 2.详细步骤解析 1.构造增删改查url,反向解析 2.ModelForm定制add.edit页面 3.starak中的 ...

  7. Memcached 集群架构与memcached-session-manager

    Memcached 集群架构方面的问题_知识库_博客园https://kb.cnblogs.com/page/69074/ memcached-session-manager配置 - 学习中间件调优管 ...

  8. python3 网页下拉框和悬浮框操作基础汇总

    #悬浮定位操作 from selenium.webdrier import ActionChains #浏览器实例化 #定位移动的位置赋给一个参数 ActionChains(浏览器).move_to_ ...

  9. MyEclipse配置tomcat报错 - java.lang.UnsupportedClassVersionError: org/apache/lucene/store/Directory : Unsupported major.minor version 51.0

    1 开发Servlet程序时,MyEclipse配置好tomcat与JDK之后,启动时控制台报下列错误: 1 java.lang.UnsupportedClassVersionError: org/a ...

  10. 非关系型数据库----MongoDB

    一.什么是MongoDB? MongoDB 是由C++语言编写的,是一个基于分布式文件存储的开源数据库系统. 在高负载的情况下,添加更多的节点,可以保证服务器性能. MongoDB 旨在为WEB应用提 ...