## 10235 - Simply Emirp

Moderator: Board moderators

Notice
Emirp is a prime number that produces different prime number when reversed not the same.

Okay?

Hope this helps! Keep posting.
Solving for fun..

linux
Learning poster

Posts: 56
Joined: Sat Jul 01, 2006 12:21 pm

razor_blue
New poster

Posts: 27
Joined: Mon Nov 27, 2006 4:44 am
Location: Indonesia

Here:
Code: Select all
` if(b==d && prime(b)==b)printf("%d is prime.\n",b);else if(prime(b)==b && prime(d)==d)printf("%d is emirp.\n",b);else if(prime(b)==b || prime(d)==d)printf("%d is prime.\n",b);else printf("%d is not prime.\n",b);`

I don't think you need to check if b==d , also see if (prime(b)==0 not b.
(If i get right when prime(n)==0 then n=0)
Do this:
if(prime(b)!=0) -> No prime
else if(prime(b)==0 && prime(d)!=0) -> Is prime
else -> Is emirp
I don't think you need long int, i use simple int and got AC
/*No Comment*/

New poster

Posts: 13
Joined: Sun Mar 04, 2007 8:40 pm

i tried but

WA
if anyone check why
this is
WA
Last edited by bishop on Mon Jun 11, 2007 8:18 pm, edited 1 time in total.
bishop
New poster

Posts: 43
Joined: Fri May 04, 2007 12:57 pm

Check the following line.
Code: Select all
`else if(prime(n) || prime(rev))`

29 is a prime, isn't it?
Ami ekhono shopno dekhi...
HomePage
Jan
Guru

Posts: 1334
Joined: Wed Jun 22, 2005 10:58 pm

only if reverse number is prime
result is not prime
i got it

thanx
a lot
bishop
New poster

Posts: 43
Joined: Fri May 04, 2007 12:57 pm

Why it is wrong,
Code: Select all
`Hmmmmmmm, AC`
Last edited by Bad Boy on Mon Jul 16, 2007 5:17 pm, edited 2 times in total.
New poster

Posts: 3
Joined: Fri Jul 13, 2007 5:17 am
Location: CSE, DU(13th)

2, 3, 5, 7, 11 ... these are primes, not emirps. Read the description again to find the reason.
Ami ekhono shopno dekhi...
HomePage
Jan
Guru

Posts: 1334
Joined: Wed Jun 22, 2005 10:58 pm

### Re: 10235 WA

i am not finding the reason of getting wa??????/
here is my code................

Code: Select all
`/*****  simply emirp @ 10235  *****/#include<stdio.h>#include<math.h>long isPrime(long p) {    long s;   s=long(sqrt(p));   //if(p==1) return 1;     //if(p==2) return 1;     if(p%2==0) return 0;     for(long i=3;i<=s+1;i+=2)         if(p%i==0)          return 0;    return 1;}long RevisPrime(long q){   long r;   long val=0;   for(;q;q/=10)      val = val*10 + q%10;   r=long(sqrt(val));   //if(val==1)   return 1;   //if(val==2)   return 1;   if(val%2==0)   return 0;   for(long k=3;k<=r+1;k+=2)      if(val%k==0)         return 0;   return 1;}int main(){   long num;   long t1,t2;   while(scanf("%ld",&num)==1)   {      t1=isPrime(num);      t2=RevisPrime(num);      if(num==2||num==3||num==5||num==7||num==11)         printf("%ld is prime.\n",num);            else if(t1==0)         printf("%ld is not prime.\n",num);      else if(t1==1 && t2==1)         printf("%ld is emirp.\n",num);      else if(t1==1 && t2==0)         printf("%ld is prime.\n",num);   }   return 0;}`

Code: Select all
`keep dreaming...`
apurba
New poster

Posts: 42
Joined: Sun Oct 07, 2007 10:29 pm
Location: In Front of Computer

### Re: 10235 WA

I don't know why am i getting WA too,
I think i read the problem description very carefully

Code: Select all
`Removed After AC`
Last edited by amr saqr on Thu May 01, 2008 5:01 pm, edited 1 time in total.
C++ Is The Best.
amr saqr
New poster

Posts: 29
Joined: Tue Mar 11, 2008 6:35 pm

### Re: 10235 WA

You forgot to write a terminating \0 to string in this part of your code:
amr saqr wrote:
Code: Select all
`         int index=0,temp=number;         while (temp!=0)         {            n[index]=temp%10+'0';            temp/=10;            index++;         }         int t=atoi(n);`
mf
Guru

Posts: 1244
Joined: Mon Feb 28, 2005 4:51 am
Location: Zürich, Switzerland

### Re: 10235 WA

Thanx so much (mf)
i modified my code and got AC
C++ Is The Best.
amr saqr
New poster

Posts: 29
Joined: Tue Mar 11, 2008 6:35 pm

### Re: 10235 - Simply Emirp

why i got WA ?
i cant understand..
pls someone help me..
pls pls..

Code: Select all
`AC..removed after AC..`

pok
New poster

Posts: 25
Joined: Sun Nov 09, 2008 11:04 pm

### Re: 10235 - Simply Emirp

Can anyone point out the mistake in my program...

Code: Select all
`#include<stdio.h>#include<stdlib.h>#include<string.h>#define max 1000000bool pr[max+1];int prime[max];int main(){      long int ns,re;   int len,r,fg;   char in[10],rev[10];   //generating primes   pr[0]=true;   pr[1]=true;   for(int i=2;i*i<=max;i++)   {         if(pr[i]==true)            continue;      for(int j=i+i;j<=max;j=j+i)         pr[j]=true;      //generating ends;   }   //program starts   while(gets(in))   {      ns=atol(in);      if(pr[ns]==true)      {         printf("%ld is not prime.\n",ns);         continue;      }      else      {         len=strlen(in);         r=0;         fg=1;         for(int k=len-1;k>=0;k--)         {            if(in[k]!='0')               rev[r++]=in[k];         }                     rev[r]='\0';         re=atol(rev);         //printf("%ld",re);         if(pr[re]==false && re!=ns)            fg++;      }      if(fg==1)         printf("%ld is prime.\n",ns);      else if(fg==2)         printf("%ld is emirp.\n",ns);      }return 0;}`

asif_khan_ak_07
New poster

Posts: 25
Joined: Fri Apr 17, 2009 8:24 am

### Re: 10235 - Simply Emirp

What's wrong with my code?!! I checked every sample output from this post & my code generate correct ans. but got WA in uva. plz help me.
Code: Select all
`#include<stdio.h>#include<math.h>int main(){   long int n,n1,rs;   int i,j,r;   bool chk,chk2;    while(scanf("%ld",&n)!=EOF)    {        chk=true;        if(n==0 || n==1)            chk=false;        for(i=2;i<sqrt(n);i++)            if(n%i==0)                chk=false;        if(chk==false)            printf("%ld is not prime.\n",n);        else        {            chk2=true;            rs=0;            n1=n;            while(n!=0)            {                r=n%10;                rs=rs*10+r;                n=n/10;            }            for(j=2;j<sqrt(rs);j++)                if(rs%j==0)                    chk2=false;            if(rs==n1)                printf("%ld is prime.\n",n1);            else if(chk2==true)                printf("%ld is emirp.\n",n1);            else if(chk==true)                printf("%ld is prime.\n",n1);        }    }    return 0;}`

plz...............
tanvirfromhell
New poster

Posts: 5
Joined: Sat Apr 16, 2011 7:42 pm

Previous