20分求助

P1307 [NOIP2011 普及组] 数字反转

Rosy1 @ 2023-08-26 18:57:02

#include<bits/stdc++.h>
using namespace std;
int main( )
{
    int x,ge,shi,bai,y;
    cin>>x;
    bai=x%10;
    shi=x/10%10;
    ge=x/100%10;
    y=bai*100+shi*10+ge;
    cout<<y; 
    return 0;
}

by zyhe2013 @ 2023-08-26 18:59:03

#include<bits/stdc++.h> 
using namespace std;
const int N=10000001;
long long n,m,pis[N],vis[N],cnt;
queue<long long> q;
stack<long long> s;
bool check(){
    while(!q.empty() && !s.empty()){
        if(q.front()!=s.top()){
            return false;
        }
        q.pop();
        s.pop();
    }
    return true;
}
void primes(){
    for(long long i=2;i<=N;i++){
        if(pis[i]==0) vis[++cnt]=i;
        for(long long j=1;j<=cnt && i*vis[j]<=N;j++){
            pis[i*vis[j]]=1;
            if(i%vis[j]==0) break;
        }
    }
}
int main(){
    cin>>n>>m;
    primes();
    for(long long i=1;i<=cnt;i++){
        if(vis[i]>m) break;
        if(vis[i]>=n && vis[i]<=m){
            long long v=vis[i];
            while(v>0){
                q.push(v%10);
                s.push(v%10);
                v/=10;
            }
            if(check()){
                cout<<vis[i]<<endl;
            }
            while(!q.empty()) q.pop();
            while(!s.empty()) s.pop();
        }
    }
    return 0;
}

求关


by liu_le_chen @ 2023-08-26 19:16:08

@zyhe2023 你发的代码为什么是我的回文质数呀


by SMall_X_ @ 2023-08-26 19:23:28

题目没说是三位数鸭……


|