10235  Simply Emirp
Moderator: Board moderators
I have received your codes~
I have not taken a indepth look at it, but I just have done an interesting thing: I use a program to generate a file consisting of 2,3,4,5,...,999999, then use this file as the input file of my program and your program. Finally, I diff the output file generated by the two program and found that..... NO DIFFERENCE (at least found by the diff program in UNIX)
I can be sure that your program is of no problem~
Or something not releted to the problem introduces the WA~ e.g. submitted with wrong problem number? Haha.....
I have not taken a indepth look at it, but I just have done an interesting thing: I use a program to generate a file consisting of 2,3,4,5,...,999999, then use this file as the input file of my program and your program. Finally, I diff the output file generated by the two program and found that..... NO DIFFERENCE (at least found by the diff program in UNIX)
I can be sure that your program is of no problem~
Or something not releted to the problem introduces the WA~ e.g. submitted with wrong problem number? Haha.....
10235 emirp definition
I'm a bit confused about emirp ,can anyone define emirp more
clearly???
why 2 is not emirp ?????
thx in advance.
clearly???
why 2 is not emirp ?????
thx in advance.
I quote from the problem statement:
2 is not different than 2 when reversed...An Emirp (Prime spelt backwards) is a Prime that gives you a different Prime when its digits are reversed
K M Hasan
http://www.cs.umanitoba.ca/~kmhasan/
http://www.cs.umanitoba.ca/~kmhasan/
10235 Emirp Why WA
if anyone can tell me why
this program is wrong
.... I would be very grateful.
#include<stdio.h>
#include<math.h>
int chkprime(unsigned long);
int main()
{
int k=0,cnt=0,j,in;
unsigned long n,rf=0,xf,fnum[50],num;
while(scanf("%lu",&n)!=EOF)
{
num=n;
if(!(n%2)  !(n%3)) {k=0;if(n==2  n==3) k=1;}
else k=chkprime(n);
if(k==0) {printf("%lu is not prime.\n",num);continue;}
while(n!=0)
{ xf=n%10;
fnum[cnt]=xf;
n=n/10;
cnt++;
}
for(j=cnt1,in=0;j>=0;j,in++)
rf=rf+fnum[j]*pow(10,in);
if(!(rf%2)  !(rf%3)) {k=0;if(rf==2  rf==3) k=1;}
else k=chkprime(rf);
if(k==0 (num==rf)) printf("%lu is prime.\n",num);
else printf("%lu is emirp.\n",num);
cnt=0;
k=0;
rf=0;
}
return 0;
}
int chkprime(unsigned long n)
{
unsigned long d;
unsigned long i,in,p=n1;
d=1;
if(p==1) i=1;
for(in=4;in<=2147483648;in=in*2)
if(p<in) {i=in/2;break;}
for(;i>=1;i=i/2)
{
d=((d*d)%n);
if(p&i)
d=((d*2)%n);
}
if(d!=1) return 0;
if(n==3) return 1;
else if(n==5) return 1;
for(p=3;p<=sqrt(n);p+=2)
if(!(n%p)) return 0;
return 1;
}
this program is wrong
.... I would be very grateful.
#include<stdio.h>
#include<math.h>
int chkprime(unsigned long);
int main()
{
int k=0,cnt=0,j,in;
unsigned long n,rf=0,xf,fnum[50],num;
while(scanf("%lu",&n)!=EOF)
{
num=n;
if(!(n%2)  !(n%3)) {k=0;if(n==2  n==3) k=1;}
else k=chkprime(n);
if(k==0) {printf("%lu is not prime.\n",num);continue;}
while(n!=0)
{ xf=n%10;
fnum[cnt]=xf;
n=n/10;
cnt++;
}
for(j=cnt1,in=0;j>=0;j,in++)
rf=rf+fnum[j]*pow(10,in);
if(!(rf%2)  !(rf%3)) {k=0;if(rf==2  rf==3) k=1;}
else k=chkprime(rf);
if(k==0 (num==rf)) printf("%lu is prime.\n",num);
else printf("%lu is emirp.\n",num);
cnt=0;
k=0;
rf=0;
}
return 0;
}
int chkprime(unsigned long n)
{
unsigned long d;
unsigned long i,in,p=n1;
d=1;
if(p==1) i=1;
for(in=4;in<=2147483648;in=in*2)
if(p<in) {i=in/2;break;}
for(;i>=1;i=i/2)
{
d=((d*d)%n);
if(p&i)
d=((d*2)%n);
}
if(d!=1) return 0;
if(n==3) return 1;
else if(n==5) return 1;
for(p=3;p<=sqrt(n);p+=2)
if(!(n%p)) return 0;
return 1;
}

 Experienced poster
 Posts: 192
 Joined: Sat Nov 30, 2002 5:14 am
Try This Test Case :
Note : that 2 is not emirp, but prime!
Sample input:
2
1
10
11
71
9001
10009901
1321
1099933
Sample Output
2 is prime.
1 is prime.
10 is not prime.
11 is prime.
71 is emirp.
9001 is emirp.
10009901 is not prime.
1321 is emirp
1099933 is emirp.
Hope this Helps.
GOOD LUCK
RED SCORPION
Note : that 2 is not emirp, but prime!
Sample input:
2
1
10
11
71
9001
10009901
1321
1099933
Sample Output
2 is prime.
1 is prime.
10 is not prime.
11 is prime.
71 is emirp.
9001 is emirp.
10009901 is not prime.
1321 is emirp
1099933 is emirp.
Hope this Helps.
GOOD LUCK
RED SCORPION

 Learning poster
 Posts: 90
 Joined: Sat Feb 15, 2003 1:39 am
 Location: Paris, France
 Contact:
logical error i guess. modify the following code:
code to modify:
[cpp]if(isPrime(b))
if(a!=b)
printf("%lld is emirp.\n",a);
else
printf("%lld is prime.\n",a);
[/cpp]
code to replace with:
[cpp]if(isPrime(b)) {
if(a!=b)
printf("%lld is emirp.\n",a);
else
printf("%lld is prime.\n",a);
}
else
printf("%lld is prime.\n",a);
[/cpp]
and i think you should use long instead of long long.
good luck
sohel
code to modify:
[cpp]if(isPrime(b))
if(a!=b)
printf("%lld is emirp.\n",a);
else
printf("%lld is prime.\n",a);
[/cpp]
code to replace with:
[cpp]if(isPrime(b)) {
if(a!=b)
printf("%lld is emirp.\n",a);
else
printf("%lld is prime.\n",a);
}
else
printf("%lld is prime.\n",a);
[/cpp]
and i think you should use long instead of long long.
good luck
sohel
10235 Time Limit Exceeded
anyone can help me
[cpp]//10235
#include<stdio.h>
#include<string.h>
main()
{
unsigned long n=0,tr1=0,tr2=0,in1=0,in2=0,i=0,j=0,num=2;
char in[100000];
while(scanf("%s",in)==1)
{
n=strlen(in);
j=n1;
while(i<n)
{
in1=(in'0')+in1*10;
in2=(in[j]'0')+in2*10;
i++;
j;
}
while(tr1==0&&num<in1)
{
if(in1%num==0)
tr1=1;
else
num++;
}
num=2;
if(in1==in2)
tr2=1;
while(tr2==0&&num<in2)
{
if(in2%num==0)
tr2=1;
else
num++;
}
if(tr1==1)
printf("%ld is not prime.\n",in1);
else if(tr1==0&&tr2==1)
printf("%ld is prime.\n",in1);
else if(tr1==0&&tr2==0)
printf("%ld is emirp.\n",in1);
tr1=0;
tr2=0;
in1=0;
in2=0;
num=2;
i=0;
}
}[/cpp]
[cpp]//10235
#include<stdio.h>
#include<string.h>
main()
{
unsigned long n=0,tr1=0,tr2=0,in1=0,in2=0,i=0,j=0,num=2;
char in[100000];
while(scanf("%s",in)==1)
{
n=strlen(in);
j=n1;
while(i<n)
{
in1=(in'0')+in1*10;
in2=(in[j]'0')+in2*10;
i++;
j;
}
while(tr1==0&&num<in1)
{
if(in1%num==0)
tr1=1;
else
num++;
}
num=2;
if(in1==in2)
tr2=1;
while(tr2==0&&num<in2)
{
if(in2%num==0)
tr2=1;
else
num++;
}
if(tr1==1)
printf("%ld is not prime.\n",in1);
else if(tr1==0&&tr2==1)
printf("%ld is prime.\n",in1);
else if(tr1==0&&tr2==0)
printf("%ld is emirp.\n",in1);
tr1=0;
tr2=0;
in1=0;
in2=0;
num=2;
i=0;
}
}[/cpp]
1 is not prime!!Red Scorpion wrote:Try This Test Case :
Note : that 2 is not emirp, but prime!
Sample input:
2
1
10
11
71
9001
10009901
1321
1099933
Sample Output
2 is prime.
1 is prime.
10 is not prime.
11 is prime.
71 is emirp.
9001 is emirp.
10009901 is not prime.
1321 is emirp
1099933 is emirp.
Hope this Helps.
GOOD LUCK
RED SCORPION