10235  Simply Emirp
Moderator: Board moderators
Hey Hey
Hey man ,
so smart of u . u r right about the check function . it wont work for 25 nor wil it work for 16 or 9 or 36 . There will be a slight change in the operator used in the function , instead of '<' it will be '<=' ,which some how i got it right and submitted the prob and got ac . thanx for u r notice .
Riyad
so smart of u . u r right about the check function . it wont work for 25 nor wil it work for 16 or 9 or 36 . There will be a slight change in the operator used in the function , instead of '<' it will be '<=' ,which some how i got it right and submitted the prob and got ac . thanx for u r notice .
Riyad
HOLD ME NOW ,, I AM 6 FEET FROM THE EDGE AND I AM THINKIN.. MAY BE SIX FEET IS SO FAR DOWN

 New poster
 Posts: 5
 Joined: Wed Oct 22, 2003 3:29 am
 Location: dhaka
 Contact:
10235Why?.. WA
plz somebody tell me why WA?
i didn't find any mistake
[cpp]
#include<stdio.h>
long isprime(long x){
long i=2;
while(i*i<=x){
if(x%i==0) return 0;
i++;
}
return 1;
}
long rev(long x)
{
long r=0,i=1;
if(x<10) return x;
r=x;
while(r>9){
r=r/10;
i*=10;
}
r=0;
while(x>0){
r=r+((x%10)*i);
x=x/10;
i=i/10;}
return r;
}
void main()
{
long n,t;
freopen("E:\\acm\\10235.in","r",stdin);
freopen("E:\\acm\\10235.out","w",stdout);
while(scanf("%ld",&n)==1){
t=rev(n);
if(isprime(n)==0) printf("%ld not prime.\n",n);
else if(n==tisprime(t)==0) printf("%ld is prime.\n",n);
else printf("%ld is emirp.\n",n);
}
}
[/cpp]
i didn't find any mistake
[cpp]
#include<stdio.h>
long isprime(long x){
long i=2;
while(i*i<=x){
if(x%i==0) return 0;
i++;
}
return 1;
}
long rev(long x)
{
long r=0,i=1;
if(x<10) return x;
r=x;
while(r>9){
r=r/10;
i*=10;
}
r=0;
while(x>0){
r=r+((x%10)*i);
x=x/10;
i=i/10;}
return r;
}
void main()
{
long n,t;
freopen("E:\\acm\\10235.in","r",stdin);
freopen("E:\\acm\\10235.out","w",stdout);
while(scanf("%ld",&n)==1){
t=rev(n);
if(isprime(n)==0) printf("%ld not prime.\n",n);
else if(n==tisprime(t)==0) printf("%ld is prime.\n",n);
else printf("%ld is emirp.\n",n);
}
}
[/cpp]

 Experienced poster
 Posts: 136
 Joined: Tue Apr 01, 2003 6:59 am
 Location: Jakarta, Indonesia
I think you should revise your isprime() function.
For the input 6, your program will output:
6 is prime.
Where the correct output should be 6 is not prime.
Hope this helps!!
For the input 6, your program will output:
6 is prime.
Where the correct output should be 6 is not prime.
Hope this helps!!
There are 3 things one need to be successful : motivation, ability and chance. And if you're a believer, make it four : God's will.

 New poster
 Posts: 5
 Joined: Wed Oct 22, 2003 3:29 am
 Location: dhaka
 Contact:
what is wrong
i think my isprime() function is OK.
and
for 6
OUTPUT:6 is not prime(correct)
i couldn't understand that u(Joseph Kurniawan) want to say.
PLZ reply
and
for 6
OUTPUT:6 is not prime(correct)
i couldn't understand that u(Joseph Kurniawan) want to say.
PLZ reply

 Guru
 Posts: 724
 Joined: Wed Dec 19, 2001 2:00 am
 Location: Germany

 New poster
 Posts: 5
 Joined: Wed Oct 22, 2003 3:29 am
 Location: dhaka
 Contact:
just reply
i have solved the problem and got AC(without changing "isprime()").
there was some miskate.
to shamim,
should i change my ID?
shamim(aiub)
there was some miskate.
to shamim,
should i change my ID?
shamim(aiub)

 Learning poster
 Posts: 90
 Joined: Sat Feb 15, 2003 1:39 am
 Location: Paris, France
 Contact:
I tried to change my mane, but it is not an option. The board administrators chose not to let us change our name. I guess it's the right choice to prevent people change too many times. I would be confusing.shamim wrote:PS
How about changing your name if you do not mind.
I mean same name causes loss of our uniqeness.
I don't really care about changing it anmore, but if You do, the only way is to ask the administrators to do it.
They won't do it for a lot of people, though.
Not AC yet AC at last

 Experienced poster
 Posts: 136
 Joined: Tue Apr 01, 2003 6:59 am
 Location: Jakarta, Indonesia

 New poster
 Posts: 10
 Joined: Wed Dec 17, 2003 3:12 pm
 Location: Dhaka
 Contact:
10235 Why WA.
CUT
Last edited by Kamanashish on Wed Mar 17, 2004 4:08 pm, edited 1 time in total.
Work hard.

 New poster
 Posts: 50
 Joined: Wed Nov 06, 2002 1:37 pm
 Location: Planet Earth, Universe
 Contact:
http://onlinejudge.uva.es/board/viewtopic.php?t=2004
1 or 0 are not even prime. So, they can't be emirp
1 or 0 are not even prime. So, they can't be emirp
Hi,
I tested my program on all your tests,
I read all topics about 10235  Simply Emirp,
but I still get WA.
I apologise for putting my code here, but I can't work out what's wrong  it seems to be all right :/
A little explanation :
s, os  numbers read as strings : s  read normally, os  read backwards
g, og  real numbers that I am to check
n, nn  bools declaring : n  whether original number is a prime, nn  whether the same number read backwards is a prime
[pascal]
program miazio;
function odwr (s:string):string;
var
pk:byte;
qpa:string;
begin
pk:=length (s) + 1;
qpa:='';
repeat
dec (pk);
qpa:=qpa + s[pk]
until pk <= 1;
odwr:=qpa;
end;
var
s, os:string;
i, j, l, k, lp, p, g, og:longint;
n, nn:boolean;
kurde:set of char;
begin
kurde:=['0', '1', '2', '3', '4', '5', '6', '7', '8', '9'];
while not eof do
begin
readln (s);
os:=odwr (s);
g:=0; og:=0;
for lp:=1 to length (s) do
g:=g * 10 + ord (s[lp])  48;
for lp:=1 to length (os) do
og:=og * 10 + ord (os[lp])  48;
lp:=0;
k:=1;
nn:=false;
repeat
inc (k);
if og mod k = 0 then
inc (lp);
until (k = trunc (sqrt (og))+1) or (lp > 0);
if (lp = 0) then
nn:=true;
lp:=0;
k:=1;
n:=false;
repeat
inc (k);
if g mod k = 0 then
inc (lp);
until (k = trunc (sqrt (g))+1) or (lp > 0);
if lp = 0 then
n:=true;
if g = 1 then n:=true;
if og = 1 then nn:=false;
if (g = 2) then n:=true;
if og = 2 then nn:=true;
if (og = g) and (n) then nn:=false;
if (not n) and (not nn) then writeln (g, ' is not prime.');
if n and (not nn) then writeln (g, ' is prime.');
if nn then writeln (g, ' is emirp.');
n:=false;
nn:=false;
end;
end.
[/pascal]
I tested my program on all your tests,
I read all topics about 10235  Simply Emirp,
but I still get WA.
I apologise for putting my code here, but I can't work out what's wrong  it seems to be all right :/
A little explanation :
s, os  numbers read as strings : s  read normally, os  read backwards
g, og  real numbers that I am to check
n, nn  bools declaring : n  whether original number is a prime, nn  whether the same number read backwards is a prime
[pascal]
program miazio;
function odwr (s:string):string;
var
pk:byte;
qpa:string;
begin
pk:=length (s) + 1;
qpa:='';
repeat
dec (pk);
qpa:=qpa + s[pk]
until pk <= 1;
odwr:=qpa;
end;
var
s, os:string;
i, j, l, k, lp, p, g, og:longint;
n, nn:boolean;
kurde:set of char;
begin
kurde:=['0', '1', '2', '3', '4', '5', '6', '7', '8', '9'];
while not eof do
begin
readln (s);
os:=odwr (s);
g:=0; og:=0;
for lp:=1 to length (s) do
g:=g * 10 + ord (s[lp])  48;
for lp:=1 to length (os) do
og:=og * 10 + ord (os[lp])  48;
lp:=0;
k:=1;
nn:=false;
repeat
inc (k);
if og mod k = 0 then
inc (lp);
until (k = trunc (sqrt (og))+1) or (lp > 0);
if (lp = 0) then
nn:=true;
lp:=0;
k:=1;
n:=false;
repeat
inc (k);
if g mod k = 0 then
inc (lp);
until (k = trunc (sqrt (g))+1) or (lp > 0);
if lp = 0 then
n:=true;
if g = 1 then n:=true;
if og = 1 then nn:=false;
if (g = 2) then n:=true;
if og = 2 then nn:=true;
if (og = g) and (n) then nn:=false;
if (not n) and (not nn) then writeln (g, ' is not prime.');
if n and (not nn) then writeln (g, ' is prime.');
if nn then writeln (g, ' is emirp.');
n:=false;
nn:=false;
end;
end.
[/pascal]
kiha

 Learning poster
 Posts: 55
 Joined: Sat Jan 24, 2004 9:30 pm
 Location: Chittagong
 Contact: