LHX_18460366315 @ 2024-02-12 13:51:06
22分,只AC了测试点1和6,2~5 WA没有输出,7~9 TLE超时,这是为什么?望大佬求调。
#include<bits/stdc++.h>
using namespace std;
bool zhishu(long long x){
if (x <= 1){
return false;
}
for (long long i = 2;i <= sqrt(x);i++){
if (x % i == 0){
return false;
}
}
return true;
}
bool check(int x){
int a[20],flag = 1;
while (x > 0){
a[flag] = x % 10;
x /= 10;
flag++;
}
for (int i = 1; i <= flag / 2;i++){
if(a[i] != a[flag - i]){
return false;
}
}
return true;
}
bool weishu(int x){
if((1000 <= x && x <= 9999) || (100000 <= x && x <= 999999)){
return false;
}
return true;
}
int main(){
long long n,m;
cin >> n >> m;
for (long long i = n;i <= m;i += 2){
if (zhishu(i) && check(i) && weishu(i)){
printf("%ld\n",i);
}
}
return 0;
}
by QWQ_123 @ 2024-02-12 13:59:45
@ZZYX_18670145320 要是 i+=2
,
by QWQ_123 @ 2024-02-12 14:02:12
@QWQ_123 然后你这个是
然后对于长度为奇数的还要枚举中间位置
by LHX_18460366315 @ 2024-02-12 14:11:27
@QWQ_123 谢谢大佬,变成3个TLE只有66分了,怎么把它改成不超时的代码呢?