66分TLE……改scanf、printf依旧不行,求调(不会打表、算法啊……)
查看原帖
66分TLE……改scanf、printf依旧不行,求调(不会打表、算法啊……)
1130499
zhenshijuruo楼主2024/8/11 10:52

我的代码:

#include<bits/stdc++.h>
using namespace std;
bool sushu(int n) {
    if(n<=1)return false;
    for(int i=2; i<=sqrt(n);i++) {
        if(n%i==0)return false;
    }
    return true;
}
bool huiwen(int n) {
    int a=n,b=0,c;
    while(n!=0) {
        c=n%10;
        b=b*10+c;
        n/=10;
    }
    return a==b;
}
int main() {
	int a,b;
	scanf("%d%d",&a,&b);
    for (int i=a;i<b;i++) {
        if (sushu(i) && huiwen(i)) {
            printf("%d\n",i);
        }
    }
    return 0;
}

求大佬改一改,谢谢!!!

2024/8/11 10:52
加载中...