7 条题解

  • 2
    #include<stdio.h>
    #include<math.h>
    
    int is_prime(int);
    int is_superprime(int);
    
    int main()
    {
        int x, sum = 0,i;
        scanf("%d", &x);
        for (i = 2; i <= x; i++)//若i的初始值为>=3的奇数,则循环后赋值可以为i+=2
        {
            if (is_superprime(i))
                sum++;
        }
        printf("%d", sum);
    
        return 0;
    }
    
    int is_prime(int x)//判断素数函数  //x为我自己定义的变量,可以理解为输入值
    {
        if (x == 1)
            return 0;
        if (x == 2)
            return 1;
        for (int i = 2; i <=x-1; i++)//i<=sqrt(x)?
        {
            if (x % i == 0)//说明x有除了1和本身的因数
                return 0;//结束循环,该子函数返回“假”
        }
        return 1;//如果上述循环没有返回“假”,则返回“真”
    }
    int is_superprime(int x)
    {
        while (x > 0)
        {
            if (is_prime(x) == 0)
                return 0;
            x = x / 10;
        }
        return 1;
    }
    
  • 0
    @ 2022-10-03 20:57:29

    #include<stdio.h>
    int isPrime(int x);
    int main()
    {
    int n;
    scanf("%d", &n);
    int sum = 0;
    for (int i = 2; i <= n; i++) {
    sum += isPrime(i);
    }
    printf("%d", sum);
    return 0;

    }

    int isPrime(int x)
    {
    int s = 0;
    do {
    for (int i = 2; i < x; i++) {
    if (x % i == 0) {
    s++;
    break;
    }
    x /= 10;
    if (x == 1)
    s++;
    } while (x > 0);

    if (s == 0) return 1;
    else return 0;
    }

  • -1
    @ 2021-02-05 14:08:40
    #include  <iostream>
    #include  <stdio.h>
    using namespace std;
    
    int main()
    {
        int cnt=0;
        int n;cin>>n;
        for(int xx=2; xx<=n; xx++)
        {
            int x=xx;
            while(x>0) 
            {
                // x: 2333 233 23 2
                // 判断x是否是素数
                int x1 ;
                for(x1=2; x1<=x; x1++) 
                    if(x%x1==0)
                        break;
                if(x1!=x)  // x不是素数  // !!!!!
                    break; 
                x=x/10;
            }
            //cout<<"aa:"<<x<<endl;
            if(x==0)
            {
            //  cout<<xx<<"  "; 
                cnt++;
                if(cnt%10==0)
                    cout<<endl;
            }   
        }
        printf("%d",cnt);
        return 0;
    }
    
  • -1
    @ 2021-01-26 12:28:52

    #include <iostream>
    using namespace std;

    int main()
    {
    int cnt;
    int xmin;
    int xmax;
    cin>>xmax;
    for(xmin=2;xmin<=xmax;xmin++)
    {
    int x=xmin;
    while(x>0)
    {
    int x1;
    for(x1=2; x1<x; x1++)
    if(x%x1==0)
    break;
    if(x1!=x)

    break;
    x=x/10;
    }
    if(x==0)
    cnt++;
    }

    cout<<cnt<<endl;
    return 0;
    }

  • -1
    #include<iostream>
    using namespace std;
    #define NoFind -1
    #define Find 1
    
    int is_prime(int x)//素数
    {
        if(x==1)
            return NoFind;
        if(x==2)
            return Find;
        for(int i=2;i<x;i++)
        {
            if(x%i==0)
                return NoFind;
        }
        return Find;
    }
    
    int judge(int x)//超级素数
    {
        while(x>=1)
        {
            if(is_prime(x)==NoFind)
                return NoFind;
            x=x/10;
        }
        return Find;
    }
    
    int count(int x)
    {
        int flag=0;
        while(x>0)
        {
            if(judge(x)==Find)
                flag++;
            x=x-1;
        }
        return flag;
    }
    
    int main()
    {
        int x;
        cin>>x;
        cout<<count(x)<<endl;
    
        system("pause");
        return 0;
    }
        
    
  • -1
    @ 2019-10-05 02:22:34
    #include <cmath>
    using namespace std;
    int SuShuJudge(int x);
    int SuperSuShuJudge(int x);
    int SuShuJudge(int x)   //判断是否为素数
    {
        if(x==1)
            return 0;
        for(int i=2;i<=sqrt(x);i++)  //判断是否为素数,不是返回0,是返回1
        {
            if(x%i==0)
                return 0;
        }
        return 1;
    }
    int SuperSuShuJudge(int x)  //判断是否为超级素数
    {
        for(;x!=0;x/=10)  //将x除以10,逐一进行判断
        {
            if(!SuShuJudge(x))
                return 0;
        }
        return 1;
    }
    int main()
    {
        int n,num=0;
        cin>>n;
        for(int i=2;i<=n;i++)  
        {
            if(SuperSuShuJudge(i))  //如果是超级素数,则num加1
                num++;
        }
        cout<<num;
        return 0;
    }
    
    
    
  • -4

    #include<iostream>
    using namespace std;
    #define NoFind -1
    #define Find 1

    int is_prime(int x)//素数
    {
    if(x==1)
    return NoFind;
    if(x==2)
    return Find;
    for(int i=2;i<x;i++)
    {
    if(x%i==0)
    return NoFind;
    }
    return Find;
    }

    int judge(int x)//超级素数
    {
    while(x>=1)
    {
    if(is_prime(x)==NoFind)
    return NoFind;
    x=x/10;
    }
    return Find;
    }

    int count(int x)
    {
    int flag=0;
    while(x>0)
    {
    if(judge(x)==Find)
    flag++;
    x=x-1;
    }
    return flag;
    }

    int main()
    {
    int x;
    cin>>x;
    cout<<count(x)<<endl;

    system("pause");
    return 0;
    }

  • 1

信息

难度
6
分类
(无)
标签
递交数
1506
已通过
372
通过率
25%
被复制
8
上传者