1 条题解

  • 0
    @ 2025-4-7 21:29:28

    C :

    #include<stdio.h>
    #include<math.h>
    int main()
    {
    	int i,j,N;
    	scanf("%d",&N);
    	for(i=2;i<=N;i++)
    	{
    		for(j=2;j<=sqrt(i);j++)
    			if(i%j==0)
    				break;
    			if(j>sqrt(i))
    				printf("%d\n",i);
    	}
    	return 0;
    }
    
    

    C++ :

    #include<bits/stdc++.h>
    using namespace std;
    long long n,a[1000000];
    int main()
    {
    	cin>>n;
    	for(int i=2;i*i<=n;i++)
    	{
    		if(a[i]==0)
    		{
    			for(int j=i*2;j<=n;j+=i)
    			    a[j]=1;
    		}
    	}
    	for(int i=2;i<=n;i++)
    	{
    		if(a[i]==0)
    		    cout<<i<<"\n";
    	}
    		
        return 0;
    }
    
    • 1

    信息

    ID
    1610
    时间
    1000ms
    内存
    128MiB
    难度
    (无)
    标签
    递交数
    0
    已通过
    0
    上传者