Run ID 作者 问题 语言 测评结果 Time Memory 代码长度 提交时间
3120 邓小龙 超级素数 C++ Accepted 0 MS 276 KB 1061 2024-04-05 16:42:24

Tests(10/10):


Code:

#include<iostream> using namespace std; int n,st[1000001],primes[10005],pos; int ans=0; void Era(int x){ st[0]=st[1]=1; for(int i=2;i<=x/i;i++){ if(!st[i]){ for(int j=i*i;j<=x;j+=i){ st[j]=1; } } } //for(int i=1;i<=x;i++) // if(!st[i])cout<<i<<" "; } void Ola(int x){//欧拉筛将x以内的素数找出来 st[0]=st[1]=1; for(int i=2;i<=x;i++){//找100以内容的质数 if(!st[i])primes[pos++]=i; for(int j=0;j<pos&&i*primes[j]<=x;j++){ st[i*primes[j]]=1; if(i%primes[j]==0)break; } } //for(int i=0;i<pos;i++)cout<<primes[i]<<" "; //cout<<endl; } int main(){ int n; cin>>n; Era(n); //Ola(n); for(int i=1;i<=n;i++){ if(!st[i]){ int temp=i; while(temp>0){ temp/=10; if(st[temp]==1)break; } if(temp==0)ans++; } } cout<<ans<<endl; return 0; }