View Code of Problem 92

#include <stdio.h>

int main(int argv, char *argc[])
{
	int n, m, i, j, k = 0;
	int x, b, c, d;
	int a[10000] = {1, 1};
	scanf("%d%d", &m, &n);
	for(i = 2; i <= n; i++){
		if(a[i] == 0){
			for(j = i * 2; j <= n; j = j + i){
				a[j] = 1;
			}
		}
	}
	for(i = m; i <= n; i++){
		if(a[i] == 0){
			if(i < 100){
				x = i / 10;
				b = i % 10;
				if(x == b){
					printf("%6d", i);
					k++;
				}
			}else if(i < 1000){
				x = i / 100;
				b = i % 10;
				if(x == b){
					printf("%6d", i);
					k++;
				}
			}else{
				x = i / 1000;
				b = i % 10;
				d = (i % 100) / 10;
				c = i % 1000 / 100;
				if(x == b && c == d){
					printf("%6d", i);
					k++;
				}
			}
		}
		if(k == 5){
			printf("\n");
			k -= 5;
		}
	}
	printf("\n");
	return 0;
}

Double click to view unformatted code.


Back to problem 92