#include<bits/stdc++.h>
#define ll unsigned long long int
#define N 1000002
using namespace std;
int p[N+1];
void prime()
{
ll i, j;
ll l = sqrt(N);
p[0] = p[1] = 1;
for(i=2; i<=l; i++)
{
if(p[i] == 0)
{
for(j=2; i*j<=N; j++)
p[i*j] = 1;
}
}
}
int ulta(ll n)
{
ll r, s = 0, d = n;
while(n != 0)
{
r = n%10;
s = s*10 + r;
n = n/10;
}
if(d == s)
return 0;
else
{
if(p[s] == 0)
return 1;
else
return 0;
}
}
int main()
{
ll a, b, c;
prime();
while(cin >> a && 1<a < 1000000)
{
b = c = 0;
if(p[a] == 0)
{
b = 1;
c = ulta(a);
}
if(b == 1 && c == 1)
cout << a << " is emirp." << endl;
else if(b == 0 && c == 0)
cout << a << " is not prime." << endl;
else if(b == 1 && c == 0)
cout << a << " is prime." << endl;
}
return 0;
}
#define ll unsigned long long int
#define N 1000002
using namespace std;
int p[N+1];
void prime()
{
ll i, j;
ll l = sqrt(N);
p[0] = p[1] = 1;
for(i=2; i<=l; i++)
{
if(p[i] == 0)
{
for(j=2; i*j<=N; j++)
p[i*j] = 1;
}
}
}
int ulta(ll n)
{
ll r, s = 0, d = n;
while(n != 0)
{
r = n%10;
s = s*10 + r;
n = n/10;
}
if(d == s)
return 0;
else
{
if(p[s] == 0)
return 1;
else
return 0;
}
}
int main()
{
ll a, b, c;
prime();
while(cin >> a && 1<a < 1000000)
{
b = c = 0;
if(p[a] == 0)
{
b = 1;
c = ulta(a);
}
if(b == 1 && c == 1)
cout << a << " is emirp." << endl;
else if(b == 0 && c == 0)
cout << a << " is not prime." << endl;
else if(b == 1 && c == 0)
cout << a << " is prime." << endl;
}
return 0;
}
Comments
Post a Comment