Re: simply emrip 10235
Posted: Tue Nov 05, 2013 9:24 pm
An Emirp (Prime spelt backwards) is a Prime that gives you a different Prime when its digits are reversed.
Phew! Thanks so much for this and for the test case. I totally missed this while reading the problem statement.brianfry713 wrote:An Emirp (Prime spelt backwards) is a Prime that gives you a different Prime when its digits are reversed.
Code: Select all
999
481184
373
998001
998857
753257
823455
999999
850058
78887
999983
Code: Select all
999 is not prime.
481184 is not prime.
373 is prime.
998001 is not prime.
998857 is emirp.
753257 is prime.
823455 is not prime.
999999 is not prime.
850058 is not prime.
78887 is prime.
999983 is emirp.
So must check if r not equal to n to be "emirp"An Emirp (Prime spelt backwards) is a Prime that gives you a different Prime when its digits are reversed
Code: Select all
if(prime(r)==0 || r == n)
printf("%ld is prime.\n",n);
Don't forget to remove your code after getting accepted.brianfry713 wrote:101 is prime, not emirp, it has to be a different prime after reversal.
Code: Select all
#include <bits/stdc++.h>
using namespace std;
#define PB push_back
#define PF push_front
#define V vector
#define PII pair <int,int>
#define MII map <int,int>
#define MSI map <string,int>
#define MIS map <int,string>
#define MLI map <long long int,int>
#define MIL map <int,long long int>
typedef long long int LL;
typedef int I;
typedef double D;
typedef float F;
typedef bool B;
typedef char C;
typedef string S;
typedef vector <string> VS;
typedef vector <int> VI;
typedef vector <char> VC;
/* Functions */
I GCD (I x, I y){if (x%y==0) return y; else return (GCD(y,x%y));}
I prime[1002002]={0};
void init(void)
{
I i,j;
prime[0]=1;
for (i=4;i<1002002;i+=2)
{
prime[i]=1;
}
for (i=3;i<=1001;i+=2)
{
for (j=i*i;j<1002002;j+=(i+i))
{
prime[j]=1;
}
}
}
int main()
{
#ifdef DKRHZ
freopen("get.txt","r",stdin);
//freopen("got.txt","w",stdout);
#endif // DKRHZ
init();
bool p,e;
I x,n,cns;
while (scanf("%d",&n)==1)
{
x=n;
p=e=false;
if (!prime[n])
p=true;
cns=0;
while (n>0)
{
cns*=10;
cns+=n%10;
n/=10;
}
if (!prime[cns] && cns!=x)
{
e=true;
}
if (!p && !e)
{
printf("%d is not prime.\n",x);
}
else if (p && e)
{
printf("%d is emirp.\n",x);
}
else if (p && !e)
{
printf("%d is prime.\n",x);
}
}
return 0;
}
Code: Select all
#include <bits/stdc++.h>
using namespace std;
#define PB push_back
#define PF push_front
#define V vector
#define PII pair <int,int>
#define MII map <int,int>
#define MSI map <string,int>
#define MIS map <int,string>
#define MLI map <long long int,int>
#define MIL map <int,long long int>
typedef long long int LL;
typedef int I;
typedef double D;
typedef float F;
typedef bool B;
typedef char C;
typedef string S;
typedef vector <string> VS;
typedef vector <int> VI;
typedef vector <char> VC;
/* Functions */
I GCD (I x, I y){if (x%y==0) return y; else return (GCD(y,x%y));}
I prime[1002002]={0};
void init(void)
{
I i,j;
prime[0]=1;
for (i=4;i<1002002;i+=2)
{
prime[i]=1;
}
for (i=3;i<=1001;i+=2)
{
for (j=i*i;j<1002002;j+=(i+i))
{
prime[j]=1;
}
}
}
int main()
{
#ifdef DKRHZ
freopen("get.txt","r",stdin);
//freopen("got.txt","w",stdout);
#endif // DKRHZ
init();
bool p,e;
I x,n,cns;
while (scanf("%d",&n)==1)
{
x=n;
p=e=false;
if (!prime[n])
p=true;
cns=0;
while (n>0)
{
cns*=10;
cns+=n%10;
n/=10;
}
if (!prime[cns] && cns!=x)
{
e=true;
}
if (!p && !e)
{
printf("%d is not prime.\n",x);
}
else if (p && e)
{
printf("%d is emirp.\n",x);
}
else if (p && !e)
{
printf("%d is prime.\n",x);
}
}
return 0;
}