筱玛的快乐 (素数线性筛)

筛素数详见:

https://www.cnblogs.com/Miroerwf/p/7776390.html

题目链接:https://ac.nowcoder.com/acm/contest/342/A

素数线性筛。

写这篇博客是为了写一下,这道题卡素数筛,第一次用,没有裸敲过,一直用的n*sqrt(n)复杂度的。这里的是0(n)筛法。(lala())

本题比较卡时间,还要用printf。

代码:

#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int maxn=1000000+100;
int logal[100000];
int check[100000];
void lala(){
int tot = 0;
for (int i = 2; i <= 10000; ++i)
{
  if (!check[i])
  {
      if(i>2000)
    logal[++tot] = i;
  }
  for (int j = i+i; j <= 10000; j += i)
  {
    check[j] = 1;
  }
}
}
void haha(int p){
    if(p==1){
            printf("01-10\n");
        ///cout<<"01-10"<<endl;
    }
    else if(p==2){
         printf("02-20\n");
        ///cout<<"02-20"<<endl;
    }
    else if(p==3){
         printf("03-30\n");
       /// cout<<"03-30"<<endl;
    }
    else if(p==4){
         printf("10-01\n");
        ///cout<<"10-01"<<endl;
    }
    else if(p==5){
         printf("11-11\n");
       /// cout<<"11-11"<<endl;
    }
}
int main()
{
    int t,k;
    scanf("%d",&t);
    lala();
    while(t--){
        scanf("%d",&k);
        int lala=k/6;
        if(k%6==0){
                printf("%d-12-21\n",logal[k/6]);
          ///  cout<<logal[k/6]<<"-"<<"12-21"<<endl;
        }
        else{
            printf("%d-",logal[k/6+1]);
            ///  cout<<logal[k/6+1]<<"-";
            haha(k%6);
        }
    }
    return 0;
 
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值