求助!!!
查看原帖
求助!!!
542863
新时代卷王楼主2021/9/14 13:05
#include<bits/stdc++.h>
using namespace std;
int c[9];

int main()
{
    int a=0,b=0;
    int l=9;
    bool x=true,y=true;
    cin>>a>>b;
    for(int i=a;i<=b;i++)//从给定范围中寻找每一个回文素数
    {
         memset(c,0,sizeof(c));
        c[0]=i;
        for(int k=0;k<9;k++)//将数字转换成字符串
        {
            c[k+1]=c[k]/10;
            c[k]%=10;
        }
        l=9;
        while(c[l-1]==0)//求字符串长度
        {
            l--;
        }
        if(i!=11&&(l-1)%2==0)//特判
        continue;
        for(int j=2;j<=sqrt(i);j++)//判断其为素数
        {
            if(i%j==0)
            {
                x=false;
                break;
            }
        }
        if(!x)
        {
            x=true;
            continue;
        }
       
        for(int p=0;p<(l+1)/2;p++)//判断其为回文数
        {
            if(c[p]!=c[l-p-1])
            {
                y=false;
                break;
            }
            
        }
        if(!y)
        {
            y=true;
            continue;
        }
        
        cout<<i<<endl;
        i++;
    }
    
    
    
    
    
    
    return 0;
}

我啥都用了为什么还是超时

2021/9/14 13:05
加载中...