Yue_Hao @ 2024-08-17 12:26:51
dalao们帮我看一下这个代码,为啥会TLE呀(最后一个样例TLE了)?感谢
#include <bits/stdc++.h>
using namespace std;
bool pd(long long n){
for(long long i = 3; i <= ceil(sqrt(n)); i += 2) if(n % i == 0) return false;
return true;
}
bool reint(long long n){
long long nn = n;
string s = "", c;
while(nn != 0){
c = (nn % 10 + '0');
s.insert(0, c);
nn /= 10;
}
string s1 = s;
reverse(s1.begin(), s1.end());
if(s1 == s){
if( pd(n) ) return true;
else return false;
}else return false;
}
int main(){
long long a, b;
scanf("%lld %lld", &a, &b);
if(a % 2 == 0) a += 1;
for(long long i = a; i <= b; i += 2) if( reint(i) ) printf("%lld\n", i);
return 0;
}
by Yue_Hao @ 2024-08-17 13:15:44
@simple_child ,并不知道诶,我连C语言我只知道名字,并不知道风格
by Yue_Hao @ 2024-08-17 13:17:36
@simple_child ,用了,虽说没什么用,起码内存优化了一下( ( (
by simple_child @ 2024-08-17 13:19:37
@Yue_Hao 啊这……,
scanf和printf是C语言风格,cin和cout是C++风格```
(别问我为啥这么发,因为它不给发那四个单词((
by simple_child @ 2024-08-17 13:20:29
@Yue_Hao 哪个是优化时间的……
by Yue_Hao @ 2024-08-17 13:26:10
@simple_child ,emm,printf和scanf吗?
by simple_child @ 2024-08-17 13:27:31
@Yue_Hao 要用C++风格那句才有效哦
by Yue_Hao @ 2024-08-17 13:29:07
@simple_child ,哦,知道了,感谢大佬
by Yue_Hao @ 2024-08-17 13:31:16
@simple_child ,
#include <bits/stdc++.h>
using namespace std;
int main(){
//所有scanf和printf都改成了cin和cout了
return 0;
}
by Yue_Hao @ 2024-08-17 13:32:09
@simple_child ,喜提一个TLE
by Yue_Hao @ 2024-08-17 13:32:43
C语言风格全都换成了C++风格了还是TLE