最后一个测试超时,可以帮我看看为什么吗
查看原帖
最后一个测试超时,可以帮我看看为什么吗
1489953
SelinaFlora楼主2024/10/13 19:23

本人刚学c语言,头文件只知道stdio.h,所以只能达到这个水平

#include<stdio.h>
int test1(int);
int test2(int);
int test1(int n){
	int t=2;
	while(t*t<=n){
		if(n%t==0){
			return 0;
		}
		t++;
	}
	return 1;
}
int test2(int n){
	int pow[9],i=0,t=0,p;
	while(n%10!=0||n/10!=0){
		pow[i]=n%10;
		n/=10;
		i++;
	}
	p=i-1;
	while(t<=p){
		if(pow[t]!=pow[p])
			return 0;
		t++;
		p--;
	}
	return 1;
}
int main(){
	int n1,n2,t;
	scanf("%d %d",&n1,&n2);
	t=n1;
	while(t<=n2){
		if((test2(t)==1)&&(test1(t)==1)){
			printf("%d\n",t);
		}
		t++;
	}
	return 0;
}
2024/10/13 19:23
加载中...