# CQOI2016 伪光滑数

  第二个优化就是当x比较小时记忆化一下，优化明显。


#include<cstdio>
#include<cstring>
#include<algorithm>
#define fo(i,a,b) for(int i=a;i<=b;i++)
#define fd(i,a,b) for(int i=a;i>=b;i--)
using namespace std;
typedef long long ll;
ll N;
ll p[200],top;
const ll inf=3000000000000000000;
ll lim[200][200],c[200][200];
void prepare()
{
fo(i,2,128)
{
int ok=1;
fo(j,1,top)
if (i%p[j]==0) ok=0;
if (ok) p[++top]=i;
}
c[0][0]=1;
fo(i,1,100)
fo(j,0,i)
c[j][i]=(j>0?c[j-1][i-1]:0)+c[j][i-1];
}
ll f[70][3000][40];
ll dfs(ll cs,ll n,ll last)
{
if (n<3000 && f[cs][n][last]) return f[cs][n][last];
if (n==0) return 0;
if (cs==0) return 1;
if (lim[last][cs]<=n) return c[cs][last+cs];
ll re=1;
fd(i,last,1) re+=dfs(cs-1,n/p[i],i);
if (n<3000) f[cs][n][last]=re;
return re;
}
ll get(ll n)
{
ll re=0;
fo(i,1,top)
{
lim[i][1]=p[i];
fo(j,2,70)
{
lim[i][j]=lim[i][j-1]*p[i];
if (lim[i][j]/p[i]!=lim[i][j-1]) lim[i][j]=inf;
}
}
fo(i,1,top)
{
ll cs=0,tp=N;
while (tp>=p[i]) cs++,tp/=p[i];
ll num=cs-1;
re+=dfs(num,n/p[i],i);
}
return re;
}
int main()
{
prepare();
ll k;
scanf("%lld%lld",&N,&k);
ll l=1,r=N,srm=get(N),ans=0;
while (l<=r)
{
ll mid=(l+r)>>1;
if (srm-get(mid-1)>=k) ans=mid,l=mid+1; else
r=mid-1;
}
printf("%lld",ans);
}
11-19 27

04-15 1419
04-18 1110
04-12 1478
01-19 104
12-26 332
11-01 141
06-10 2728
04-13 627
04-12 1692
03-06 218
05-20 395
©️2020 CSDN 皮肤主题: 大白 设计师:CSDN官方博客