c语言求助!只有第一个点AC,其他全WA,请大佬帮忙看看!
查看原帖
c语言求助!只有第一个点AC,其他全WA,请大佬帮忙看看!
977810
yeyi030楼主2023/11/6 22:25
#include<stdio.h>


int check(int x) { //检查质数 
	int ret=1;
	for ( int i=2;i*i<=x;i++ ) {
		if ( x%i==0 ) {
			ret=0;
			break;
		}
	}
	return ret;
}

int main (void) {
	int a,b,l=0,d1,d2,d3,d4,d;
	scanf("%d%d",&a,&b);
	int c=b;
	while ( c>0 ) {
		l++;
		c/=10;
		
	}
	if ( a<=5&&b>=5 ) printf("5\n");
	if ( a<=7&&b>=7 ) printf("7\n");
	if ( a<=11&&b>=11 ) printf("11\n");
	if ( l>=3 ) {
		for ( d1=1;d1<=9;d1+=2 ) {
			for ( d2=0;d2<=9;d2++ ) {
				d=d1*100+d2*10+d1;
				if ( check(d)&&d<=b) printf("%d\n",d);
			}
		}
	}
	if ( l>=5 ) {
		for ( d1=1;d1<=9;d1+=2 ) {
			for ( d2=0;d2<=9;d2++ ) {
				for ( d3=0;d3<=9;d3++ ) {
					d=d1*10000+d2*1000+d3*100+d2*10+d3;
					if ( check(d)&&d<=b) printf("%d\n",d);
				}
			}
		}
	}
	if ( l>=7 ) {
		for ( d1=1;d1<=9;d1+=2 ) {
			for ( d2=0;d2<=9;d2++ ) {
				for ( d3=0;d3<=9;d3++ ) {
					for ( d4=0;d4<=9;d4++ ) {
						d=d1*1000000+d2*100000+d3*10000+d4*1000+d3*100+d2*10+d1;
						if ( check(d)&&d<=b) printf("%d\n",d);
					}
				}
			}
		}
	}
	
	return 0;
}
2023/11/6 22:25
加载中...