版权声明:本文为博主原创文章,转载请说明出处。 https://blog.csdn.net/xianpingping/article/details/86322219
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;
}