Untitled

mail@pastecode.io avatar
unknown
c_cpp
2 years ago
681 B
1
Indexable
Never
#include <stdio.h>

int reverse(int n) {
	int result = 0;
	while (1) {
		result = result * 10 + n % 10;
		n /= 10;
		if (n == 0) {
			break;
		}
	}
	return result;
}

int f(int n) {
	int flag = 1;
	for (int i = 2; i < n; i++) {
		if (n % i == 0) {
			flag = 0;
			break;
		}
	}
	return flag;
}

void main() {
	int m, n, count = 0;
	scanf("%d", &m);
	for (int i = 0; i < m - 1; i++) {
		scanf("%d", &n);
		if (f(n) == 1 && f(reverse(n)) == 1) {
			printf("%d is emirp.", n);
		}
		else if (f(n) == 1 && f(reverse(n)) == 0) {
			printf("%d is prime.", n);
		}
		else {
			printf("%d is not emirp.", n);
		}
	}
	printf("\n%d", reverse(199));
}