10235 - Simply Emirp
Moderator: Board moderators
2, 3, 5, 7, 11 ... these are primes, not emirps. Read the description again to find the reason.
Ami ekhono shopno dekhi...
HomePage
HomePage
Re: 10235 WA
i am not finding the reason of getting wa??????/
some one please help..............
here is my code................
thanks in advance
some one please help..............
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...
Re: 10235 WA
I don't know why am i getting WA too,
I think i read the problem description very carefully
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.
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);
Re: 10235 - Simply Emirp
why i got WA ?
i cant understand..
pls someone help me..
pls pls..

i cant understand..
pls someone help me..
pls pls..
Code: Select all
AC..
removed after AC..

-
- New poster
- Posts: 25
- Joined: Fri Apr 17, 2009 8:24 am
Re: 10235 - Simply Emirp
Can anyone point out the mistake in my program...
Thanks in advnce 
Code: Select all
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define max 1000000
bool 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;
}

10235 - SIMPLY EMIRP (help)
I gave this solution for prob-10235. But it made WRONG ANSWER. Where is the fault?
#include<stdio.h>
long int prime(long int n){
int i,a=0;
for(i=2;i<=n/2;i++){
if(n%i==0) {
a++;
break;
}
}
if(a>0) return 0;
else return 1;
}
long int reverse(long int n)
{
long int x,rev=0;
while(n>0)
{
x=n%10;
rev=(rev*10)+x;
n=n/10;
}
return rev;
}
int main()
{
long int n,rev,p,rnp;
while(scanf("%ld",&n)==1){
if(n<=1) printf("%ld is prime.\n",n);
else
{p=prime(n);
if(p==0) printf("%ld is not prime.\n",n);
else if(p==1)
{
rev=reverse(n);
rnp=prime(rev);
if(rnp==1 && n>10)printf("%ld is emirp.\n",n);
else printf("%ld is prime.\n",n);
}
}
}
return 0;
}
#include<stdio.h>
long int prime(long int n){
int i,a=0;
for(i=2;i<=n/2;i++){
if(n%i==0) {
a++;
break;
}
}
if(a>0) return 0;
else return 1;
}
long int reverse(long int n)
{
long int x,rev=0;
while(n>0)
{
x=n%10;
rev=(rev*10)+x;
n=n/10;
}
return rev;
}
int main()
{
long int n,rev,p,rnp;
while(scanf("%ld",&n)==1){
if(n<=1) printf("%ld is prime.\n",n);
else
{p=prime(n);
if(p==0) printf("%ld is not prime.\n",n);
else if(p==1)
{
rev=reverse(n);
rnp=prime(rev);
if(rnp==1 && n>10)printf("%ld is emirp.\n",n);
else printf("%ld is prime.\n",n);
}
}
}
return 0;
}
Don't Copy, Think Also
-
- New poster
- Posts: 5
- Joined: Sat Apr 16, 2011 7:42 pm
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.
plz............... 
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;
}

-
- New poster
- Posts: 25
- Joined: Thu Nov 24, 2011 6:32 am
WA in 10235
Someone please help me,I'm getting WA in 10235,I used sieve to produce primes and found correct answers for various test cases,can't think anymore,please help!!:
Here's my code,

Here's my code,
Code: Select all
#include<stdio.h>
static char sieve[1000001];
unsigned long reverse(unsigned long x)
{
unsigned long r=0;
do
{
r=r*10+(x%10);
x/=10;
}while(x);
return r;
}
int main()
{
unsigned long int i,j,n;
sieve[0]=sieve[1]=0;
for(i=2; i<100001; i++) sieve[i]=1;
for(i=2; i<1001; i++)
{
if(sieve[i]!=0)
{
for(j=i+1; j<1000001; j++)
{
if (sieve[j]!=0)
{
if((j%i)==0) sieve[j]=0;
}
}
}
}
while(scanf("%lu",&n)!=EOF)
{
if(sieve[n]==0) printf("%lu is not prime.\n",n);
else if(sieve[n]==1)
{
if((sieve[reverse(n)]==1) && (n!=reverse(n))) printf("%lu is emirp.\n",n);
else printf("%lu is prime.\n",n);
}
}
return 0;
}
Re: WA in 10235
Hello Sadia,
Welcome to UVa Forum. Here, we follow certain rules before making a post.
- It's a good idea to include the problem name in the title as well - something like "10235 - Simply Emirp". This will help everyone to identify the problem quickly.
- If there is already a thread related to your problem then make a post in that thread as opposed to creating a new one!
- Use the search option located at the top right corner to find existing discussions.
About your problem:
for(i=2; i<100001; i++) sieve=1;
I think you missed a 0?
Welcome to UVa Forum. Here, we follow certain rules before making a post.
- It's a good idea to include the problem name in the title as well - something like "10235 - Simply Emirp". This will help everyone to identify the problem quickly.
- If there is already a thread related to your problem then make a post in that thread as opposed to creating a new one!
- Use the search option located at the top right corner to find existing discussions.
About your problem:
for(i=2; i<100001; i++) sieve=1;
I think you missed a 0?
-
- New poster
- Posts: 25
- Joined: Thu Nov 24, 2011 6:32 am
Re: WA in 10235
Thanks for your kind help,it was really so stupid and frustrating,and got AC at last
And thanks for the advice,I'll remember next time

And thanks for the advice,I'll remember next time

-
- Learning poster
- Posts: 96
- Joined: Tue Jul 19, 2011 12:19 pm
- Location: Dhaka, Bangladesh
- Contact:
10235 Simple Emirp why (RE)? Please, help me please
Anyone will help me with kindly please why I am getting RE in my program?
Here, is my code:
Here, is my code:
Code: Select all
/* Removed */
Last edited by uvasarker on Wed Jan 25, 2012 9:03 am, edited 1 time in total.
-
- Guru
- Posts: 5947
- Joined: Thu Sep 01, 2011 9:09 am
- Location: San Jose, CA, USA
Re: WA in 10235
Make your sieve array global.
Check input and AC output for thousands of problems on uDebug!
-
- Learning poster
- Posts: 96
- Joined: Tue Jul 19, 2011 12:19 pm
- Location: Dhaka, Bangladesh
- Contact:
Re: WA in 10235
Hi, brother
Thanks a lots..
Thanks a lots..
Thanks a lots..
Thanks a lots..
................
..............
Thanks a lots..
Thanks a lots..
Thanks a lots..
Thanks a lots..
................
..............