石油大--2020年秋季组队训练赛第十一场----E、Give-a-Gnocchi(打表)

题面:
在这里插入图片描述
题意:
给定 n , k n,k n,k ,求不能被 ≤ n \le n n 的质数整除的第 k k k 小的合数。
其中 n ≤ 1000 , k ≤ 1000 n\le 1000,k\le1000 n1000k1000

题解:
假设 p r i m e [ i ] ≤ n   a n d   p r i m e [ i + 1 ] > n prime[i]\le n\ and\ prime[i+1]>n prime[i]n and prime[i+1]>n
本题其实要求,由 p r i m e [ i + 1 ] − − p r i m e [ i + k ] prime[i+1]--prime[i+k] prime[i+1]prime[i+k] 这些质因子所组成的合数的第 k k k 小。
很明显,答案区间在 p r i m e [ i + 1 ] 2 − − p r i m e [ i + k ] 2 prime[i+1]^2--prime[i+k]^2 prime[i+1]2prime[i+k]2 之间。

这个题其实直接 c h e c k check check 是可以过的。

但是我们可以在本地打出一张一千的表, a [ i ] a[i] a[i] 表示, n = i , k = 1000 n=i,k=1000 n=ik=1000 时,第 k k k 个符合要求的合数的值。
然后枚举质数 p r i m e [ i + 1 ] − − p r i m e [ i + k ] prime[i+1]--prime[i+k] prime[i+1]prime[i+k] 即可。跑的比较快~。

代码:

#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<string>
#include<queue>
#include<bitset>
#include<map>
#include<unordered_map>
#include<set>
namespace onlyzhao
{
    #define ui unsigned int
    #define ll long long
    #define llu unsigned ll
    #define ld long double
    #define pr make_pair
    #define pb push_back
    #define lc (cnt<<1)
    #define rc (cnt<<1|1)
    #define len(x)  (t[(x)].r-t[(x)].l+1)
    #define tmid ((l+r)>>1)
    #define fhead(x) for(int i=head[(x)];i;i=nt[i])
    #define max(x,y) ((x)>(y)?(x):(y))
    #define min(x,y) ((x)>(y)?(y):(x))
    #define one(n) for(int i=1;i<=(n);i++)
    #define rone(n) for(int i=(n);i>=1;i--)
    #define fone(i,x,n) for(int i=(x);i<=(n);i++)
    #define frone(i,n,x) for(int i=(n);i>=(x);i--)
    #define fonk(i,x,n,k) for(int i=(x);i<=(n);i+=(k))
    #define fronk(i,n,x,k) for(int i=(n);i>=(x);i-=(k))
    #define two(n,m) for(int i=1;i<=(n);i++) for(int j=1;j<=(m);j++)
    #define ftwo(i,n,j,m) for(int i=1;i<=(n);i++) for(int j=1;j<=(m);j++)
    #define fvc(vc) for(int i=0;i<vc.size();i++)
    #define frvc(vc) for(int i=vc.size()-1;i>=0;i--)
    #define forvc(i,vc) for(int i=0;i<vc.size();i++)
    #define forrvc(i,vc) for(int i=vc.size()-1;i>=0;i--)
    #define cls(a) memset(a,0,sizeof(a))
    #define cls1(a) memset(a,-1,sizeof(a))
    #define clsmax(a) memset(a,0x3f,sizeof(a))
    #define clsmin(a) memset(a,0x80,sizeof(a))
    #define cln(a,num) memset(a,0,sizeof(a[0])*num)
    #define cln1(a,num) memset(a,-1,sizeof(a[0])*num)
    #define clnmax(a,num) memset(a,0x3f,sizeof(a[0])*num)
    #define clnmin(a,num) memset(a,0x80,sizeof(a[0])*num)
    #define sc(x) scanf("%d",&x)
    #define sc2(x,y) scanf("%d%d",&x,&y)
    #define sc3(x,y,z) scanf("%d%d%d",&x,&y,&z)
    #define scl(x) scanf("%lld",&x)
    #define scl2(x,y) scanf("%lld%lld",&x,&y)
    #define scl3(x,y,z) scanf("%lld%lld%lld",&x,&y,&z)
    #define scf(x) scanf("%lf",&x)
    #define scf2(x,y) scanf("%lf%lf",&x,&y)
    #define scf3(x,y,z) scanf("%lf%lf%lf",&x,&y,&z)
    #define scs(x) scanf("%s",x+1)
    #define scs0(x) scanf("%s",x)
    #define scline(x) scanf("%[^\n]%*c",x+1)
    #define scline0(x) scanf("%[^\n]%*c",x)
    #define pcc(x) putchar(x)
    #define pc(x) printf("%d\n",x)
    #define pc2(x,y) printf("%d %d\n",x,y)
    #define pc3(x,y,z) printf("%d %d %d\n",x,y,z)
    #define pck(x) printf("%d ",x)
    #define pcl(x) printf("%lld\n",x)
    #define pcl2(x,y) printf("%lld %lld\n",x,y)
    #define pcl3(x,y,z) printf("%lld %lld %d\n",x,y,z)
    #define pclk(x) printf("%lld ",x)
    #define pcf2(x) printf("%.2f\n",x)
    #define pcf6(x) printf("%.6f\n",x)
    #define pcf8(x) printf("%.8f\n",x)
    #define pcs(x) printf("%s\n",x+1)
    #define pcs0(x) printf("%s\n",x)
    #define pcline(x) printf("%d**********\n",x)
    #define casett int tt;sc(tt);int pp=0;while(tt--)

    char buffer[100001],*S,*T;
    inline char Get_Char()
    {
        if (S==T)
        {
            T=(S=buffer)+fread(buffer,1,100001,stdin);
            if (S==T) return EOF;
        }
        return *S++;
    }
    inline int read()
    {
        char c;int re=0;
        for(c=Get_Char();c<'0'||c>'9';c=Get_Char());
        while(c>='0'&&c<='9') re=re*10+(c-'0'),c=Get_Char();
        return re;
    }
};
using namespace onlyzhao;
using namespace std;

const int inf=0x3f3f3f3f;
const ll lnf=0x3f3f3f3f3f3f3f3f;
const double dnf=1e18;
const int mod=998244353;
const double eps=1e-8;
const double pi=acos(-1.0);
const int hp=13331;
const int maxn=100100;
const int maxm=100100;
const int up=100100;

int prime[maxn],cnt=0;
bool ha[maxn];
int n,k;

void Prime(void)
{
    ha[1]=true;
    for(int i=2;i<maxn;i++)
    {
        if(!ha[i]) prime[++cnt]=i;
        for(int j=1;j<=cnt&&i*prime[j]<maxn;j++)
        {
            ha[i*prime[j]]=true;
            if(i%prime[j]==0) break;
        }
    }
}

vector<int>vc;
int pos=0,r;
int a[]={0,1475069,1475069,1475069,1475069,1455497,1455497,1455497,1455497,1455497,1455497,1440097,1440097,1440097,1440097,1440097,1440097,1440097,1440097,1422349,1422349,1422349,1422349,1422349,1422349,1405913,1405913,1405913,1405913,1405913,1405913,1387459,1387459,1387459,1387459,1369453,1369453,1369453,1369453,1369453,1369453,1369453,1369453,1369453,1369453,1369453,1369453,1369453,1369453,1352161,1352161,1352161,1352161,1352161,1352161,1335923,1335923,1335923,1335923,1335923,1335923,1319177,1319177,1319177,1319177,1302139,1302139,1302139,1302139,1302139,1302139,1302139,1302139,1286993,1286993,1286993,1286993,1286993,1286993,1286993,1286993,1286993,1286993,1269557,1269557,1269557,1269557,1269557,1269557,1269557,1269557,1253843,1253843,1253843,1253843,1238231,1238231,1238231,1238231,1238231,1238231,1238231,1238231,1238231,1238231,1238231,1238231,1238231,1238231,1238231,1238231,1238231,1238231,1238231,1238231,1220881,1220881,1220881,1220881,1206047,1206047,1190297,1190297,1190297,1190297,1173031,1173031,1173031,1173031,1173031,1173031,1173031,1173031,1173031,1173031,1173031,1173031,1173031,1173031,1158371,1158371,1158371,1158371,1142623,1142623,1127941,1127941,1127941,1127941,1114133,1114133,1114133,1114133,1114133,1114133,1114133,1114133,1114133,1114133,1114133,1114133,1114133,1114133,1099517,1099517,1099517,1099517,1099517,1099517,1099517,1099517,1099517,1099517,1083503,1083503,1070239,1070239,1070239,1070239,1055711,1055711,1041629,1041629,1041629,1041629,1041629,1041629,1041629,1041629,1041629,1041629,1026827,1026827,1013473,1013473,1013473,1013473,1013473,1013473,1013473,1013473,1013473,1013473,1013473,1013473,998911,998911,998911,998911,998911,998911,998911,998911,998911,998911,985373,985373,985373,985373,985373,985373,985373,985373,985373,985373,985373,985373,985373,985373,969491,969491,969491,969491,957149,957149,957149,957149,957149,957149,957149,957149,941789,941789,941789,941789,929167,929167,929167,929167,929167,929167,915163,915163,915163,915163,915163,915163,915163,915163,901951,901951,901951,901951,888673,888673,888673,888673,888673,888673,875053,875053,875053,875053,875053,875053,862717,862717,862717,862717,862717,862717,862717,862717,849859,849859,849859,849859,849859,849859,849859,849859,849859,849859,836461,836461,836461,836461,836461,836461,836461,836461,823987,823987,823987,823987,823987,823987,823987,823987,823987,823987,809933,809933,809933,809933,809933,809933,809933,809933,798011,798011,798011,798011,798011,798011,784319,784319,784319,784319,772801,772801,772801,772801,772801,772801,772801,772801,772801,772801,772801,772801,759907,759907,747491,747491,747491,747491,747491,747491,735577,735577,735577,735577,735577,735577,723629,723629,723629,723629,712337,712337,700559,700559,700559,700559,700559,700559,700559,700559,700559,700559,689083,689083,689083,689083,689083,689083,689083,689083,689083,689083,689083,689083,677867,677867,666949,666949,666949,666949,655297,655297,655297,655297,655297,655297,644263,644263,644263,644263,644263,644263,633779,633779,623039,623039,623039,623039,623039,623039,612701,612701,612701,612701,612701,612701,602491,602491,602491,602491,602491,602491,602491,602491,602491,602491,592187,592187,592187,592187,592187,592187,581593,581593,571247,571247,571247,571247,571247,571247,561311,561311,561311,561311,561311,561311,551987,551987,551987,551987,551987,551987,551987,551987,551987,551987,541687,541687,541687,541687,541687,541687,531389,531389,531389,531389,531389,531389,531389,531389,531389,531389,531389,531389,531389,531389,531389,531389,531389,531389,521473,521473,511741,511741,511741,511741,511741,511741,511741,511741,511741,511741,511741,511741,502009,502009,502009,502009,502009,502009,492179,492179,492179,492179,482893,482893,482893,482893,482893,482893,482893,482893,473323,473323,473323,473323,463081,463081,463081,463081,463081,463081,463081,463081,453751,453751,453751,453751,453751,453751,453751,453751,453751,453751,453751,453751,444853,444853,444853,444853,435199,435199,426367,426367,426367,426367,417889,417889,417889,417889,417889,417889,417889,417889,409039,409039,409039,409039,409039,409039,400289,400289,400289,400289,391973,391973,391973,391973,391973,391973,383407,383407,376111,376111,376111,376111,376111,376111,376111,376111,376111,376111,368351,368351,359999,359999,359999,359999,359999,359999,359999,359999,359999,359999,352211,352211,352211,352211,352211,352211,352211,352211,344459,344459,344459,344459,336517,336517,336517,336517,336517,336517,336517,336517,328841,328841,328841,328841,328841,328841,321389,321389,321389,321389,314087,314087,314087,314087,314087,314087,306611,306611,306611,306611,306611,306611,298901,298901,298901,298901,298901,298901,298901,298901,291937,291937,291937,291937,291937,291937,284891,284891,284891,284891,277931,277931,271477,271477,271477,271477,271477,271477,271477,271477,271477,271477,264623,264623,264623,264623,264623,264623,258079,258079,258079,258079,258079,258079,258079,258079,258079,258079,258079,258079,258079,258079,251659,251659,251659,251659,244991,244991,238367,238367,238367,238367,232273,232273,232273,232273,232273,232273,232273,232273,232273,232273,232273,232273,232273,232273,225847,225847,225847,225847,225847,225847,225847,225847,225847,225847,218957,218957,212983,212983,212983,212983,207001,207001,207001,207001,207001,207001,201217,201217,195287,195287,195287,195287,195287,195287,189571,189571,189571,189571,189571,189571,183893,183893,183893,183893,183893,183893,178111,178111,178111,178111,178111,178111,178111,178111,178111,178111,173203,173203,167749,167749,167749,167749,167749,167749,162373,162373,162373,162373,157601,157601,152771,152771,152771,152771,147463,147463,147463,147463,147463,147463,147463,147463,147463,147463,147463,147463,142913,142913,142913,142913,142913,142913,142913,142913,142913,142913,142913,142913,137783,137783,133141,133141,133141,133141,128633,128633,124009,124009,124009,124009,124009,124009,124009,124009,124009,124009,119279,119279,115439,115439,115439,115439,115439,115439,110893,110893,110893,110893,110893,110893,107047,107047,107047,107047,102941,102941,102941,102941,102941,102941,98723,98723,98723,98723,98723,98723,94957,94957,91027,91027,91027,91027,91027,91027,91027,91027,91027,91027,87173,87173,83593,83593,83593,83593,83593,83593,79969,79969,79969,79969,76459,76459,76459,76459,76459,76459,76459,76459,76459,76459,76459,76459,76459,76459,72731,72731,72731,72731,69323,69323,65939,65939,65939,65939,62807,62807,59893,59893,59893,59893,56743,56743,56743,56743,56743,56743,56743,56743,53531,53531,53531,53531,53531,53531,50689,50689,50689,50689,47851,47851,47851,47851,47851,47851,45041,45041,42521,42521,42521,42521,39913,39913,39913,39913,39913,39913,37319,37319,34987,34987,34987,34987,34987,34987,32639,32639,32639,32639,32639,32639,30167,30167,30167,30167,27877,27877,25811,25811,25811,25811,23729,23729,23729,23729,23729,23729,21629,21629,19651,19651,19651,19651,19651,19651,17621,17621,17621,17621,15539,15539,13549,13549,13549,13549,11419,11419,9509,9509,9509,9509,7181,7181,5005,5005,2817,1197};
void dfs(int cnt,int now)
{
    if(cnt==pos+k)
    {
        if(now!=1&&(now>=maxn||ha[now]==true)) vc.pb(now);
        return ;
    }
    if(now>r) return ;
    ll ans=now;
    for(;ans<=r;ans*=prime[cnt])
        dfs(cnt+1,ans);
}

int main(void)
{
    Prime();

    scanf("%d%d",&n,&k);
    r=a[1000-n+1];
    for(int i=1;i<=cnt;i++)
    {
        if(prime[i]>n)
        {
            pos=i;
            break;
        }
    }
    dfs(pos,1);
    sort(vc.begin(),vc.end());
    printf("%d\n",vc[k-1]);
    return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值