質數進階

 avatar
user_3763047219
c_cpp
2 years ago
900 B
1
Indexable
Never
#include <stdio.h>
#define MAXSIZE 100

int main()
{
	int sum;
	int primearrey[MAXSIZE] = {};
	int num,num2,count1=0,prime=0,rev=0,count2=0;
	scanf("%d", &sum);
	for (int i = 0;i < sum;i++) {
		scanf("%d", &primearrey[i]);
	}
	for (int i = 0;i < sum;i++) {
		num2 = primearrey[i];
		rev = 0;
		count1 = 0;
		count2 = 0;
		while (num2 >= 1) {
			rev = rev * 10 + num2 % 10;
			num2 = num2 / 10;
		}

		for (int j = 2;j < primearrey[i];j++) {
			if (primearrey[i] % j == 0) {
				count1 = count1 + 1;
			}
		}
		for (int j = 2;j < rev;j++) {
			if (rev % j == 0) {
				count2 = count2 + 1;
			}
		}
		if (count1 != 0) {
			printf("%d is not prime.", primearrey[i]);
		}
		else if (count1 == 0 && count2 == 0 && primearrey[i] != rev) {
			printf("%d is emirp.", primearrey[i]);
		}
		else {
			printf("%d is prime.", primearrey[i]);
		}
		printf("\n");
	}
	
}