Description

If a number  n≥2   has only two factors, 1 and itself, we call it a prime number. But have you ever reversed the prime number? For most prime numbers, the reverse is Will get a combined number (for example: 43 becomes 34)

若某數 n≥2且只有1和自己本身兩個因數,則我們稱之為質數(prime number),但你有曾把質數倒過來過嗎?對大部分質數來說,倒過來將得到一個組合數(例如:43變成34)

Now we define emirp (which is the reverse of prime): If the prime number is still a prime number after being reversed, and it is different from the original prime number, then we call this number an emirp number (for example: 17 reversed is 71. If they are both prime numbers, 17 is emirp).

現在我們定義 emirp(就是 prime 的反過來):如果質數反過來之後仍然是質數,並且和原先的質數不同,則我們稱這個數為 emirp number (例如:17 倒過來是 71 皆為質數則 17 為 emirp)。

Input

The input contains an integer �n.

輸入包含一個整數�n

Output

If �n is a prime number and is also a prime number when reversed, the output is n is a emirp. If �n is a prime number but not when reversed, the output is n is a prime. If �n is not a prime number, the output is n isn't. a prime.

若�n是質數,倒過來後也是質數則輸出 n is a emirp,若 �n 是質數但倒過來後不是,則輸出 n is a prime,若�n不是質數則輸出 n isn't a prime.

Sample Input 1

Sample Input 2

17
19

Sample Output 1

Sample Output 2

17 is a emirp.
19 is a prime.

Sample Input 3

18

Sample Output 3

18 isn't a prime.
#include<stdio.h>
#include<stdlib.h>
#include<math.h>

int isPrime(int n){
	int b = 0;
	for(int i = 2; i<n; i++){
		if(n%i==0){
			b++;
			return b;
		}
	}
	return 0;
}

int inverseNum(int n){
	int c=0;
	for(int i = n; i>0; i=i/10){
			c++;
		}
	int a[c];
	int d = 1;
	for(int i = 0; i<c; i++){
		a[i] = n - n/10*10;
		n=n/10;
	}
	for(int i = c; i>0;i--){
		d = d*10;
	}
	for(int i = 0; i<c; i++){
		d=d/10;
		n = n +a[i]*d;
		
	}
	return n;
	

}

int main(){
	int n;
//	b is counter, 0 is not prime, 1 is prime, 2 is emirp
//c is counter
	int b = 0;
	int c = 0;
	scanf("%d",&n);
	b = isPrime(n);

	if(b==0){
//		this is to find theamount of 10's there are
		c = inverseNum(n);
		if(isPrime(c)==0){
			printf("%d is a emirp.",n);
		}else{
			printf("%d is a prime.",n);
		}
		
		

	}else{
		printf("%d isn't a prime.",n);
		return 0;
		}

	}

is Prime function and inverse Number function are above.

standard sample answer:

(CPE) Simply Emirp 若某數 n>=2 且只有1和自己本身兩個因數,則我們稱之為質數(prime number), 但你有曾把質數倒過來過嗎?對大部分質數來說,倒過來將得到一個組合數(例如:43變成34) 現在我們定義 emirp(就是 prime 的反過來):如果質數反過來之後仍然是質數,並且和原先的質數不同, 則我們稱這個數為 emirp number (例如:17 倒過來是 71 皆為質數則 17 為 emirp)。