1 条题解

  • 0
    @ 2025-10-8 16:48:10

    scy视频

    20分代码:

    #include<bits/stdc++.h>
    using namespace std;
    typedef long long LL;
    LL a[110];
    bool pd(LL x)
    {
        if(x<2) return 0;
        for(LL i=2;i<x;i++)
            if(x%i==0)
            {
                return 0; 
            }
        return 1;
    }
    int main()
    {
        int n;scanf("%d", &n);
        for(int i=1;i<=n;i++)
        {
            scanf("%lld", &a[i]);
            if( pd(a[i])==1 )
            {
                printf("%lld ", a[i]);
            }
        }
        return 0;
    }
    

    40分代码:

    #include<bits/stdc++.h>
    using namespace std;
    typedef long long LL;
    LL a[110];
    bool pd(LL x)
    {
        if(x<2) return 0;
        for(LL i=2;i<=x/2;i++)
            if(x%i==0)
            {
                return 0; 
            }
        return 1;
    }
    int main()
    {
        int n;scanf("%d", &n);
        for(int i=1;i<=n;i++)
        {
            scanf("%lld", &a[i]);
            if( pd(a[i])==1 )
            {
                printf("%lld ", a[i]);
            }
        }
        return 0;
    }
    

    100分代码:

    #include<bits/stdc++.h>
    using namespace std;
    typedef long long LL;
    LL a[110];
    bool pd(LL x)
    {
    	if(x<2) return 0;
        for(LL i=2;i<=sqrt(x+1);i++)
            if(x%i==0)
            {
                return 0; 
            }
        return 1;
    }
    int main()
    {
        int n;scanf("%d",&n);
        for(int i=1;i<=n;i++)
        {
            scanf("%lld",&a[i]);
            if( pd(a[i])==1 )
            {
                printf("%lld ",a[i]);
            }
        }
        return 0;
    }
    
    • 1

    *【C++语言:函数】质数筛选(视频)

    信息

    ID
    17
    时间
    300ms
    内存
    128MiB
    难度
    9
    标签
    递交数
    1576
    已通过
    138
    上传者