10235 - Simply Emirp

All about problems in Volume 102. If there is a thread about your problem, please use it. If not, create one with its number in the subject.

Moderator: Board moderators

User avatar
Riyad
Experienced poster
Posts: 131
Joined: Thu Aug 14, 2003 10:23 pm
Location: BUET
Contact:

Hey Hey

Post by Riyad »

Hey man ,
so smart of u :o . 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
shamim(aiub)
New poster
Posts: 5
Joined: Wed Oct 22, 2003 3:29 am
Location: dhaka
Contact:

10235-Why?.. WA

Post by shamim(aiub) »

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==t||isprime(t)==0) printf("%ld is prime.\n",n);
else printf("%ld is emirp.\n",n);
}
}

[/cpp]
Joseph Kurniawan
Experienced poster
Posts: 136
Joined: Tue Apr 01, 2003 6:59 am
Location: Jakarta, Indonesia

Post by Joseph Kurniawan »

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!! :wink: :wink:
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.
shamim(aiub)
New poster
Posts: 5
Joined: Wed Oct 22, 2003 3:29 am
Location: dhaka
Contact:

what is wrong

Post by shamim(aiub) »

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
Adrian Kuegel
Guru
Posts: 724
Joined: Wed Dec 19, 2001 2:00 am
Location: Germany

Post by Adrian Kuegel »

Your isprime function is wrong for 1.
But anyway, as it is said that the input number n is > 1 this is not your problem. What about comparing your output to the sample output? I think you will see your mistake easily :)
shamim
A great helper
Posts: 498
Joined: Mon Dec 30, 2002 10:10 am
Location: Bozeman, Montana, USA

Post by shamim »

HI Shamim!

I found one mistake in your code,

for 18, your output is
18 not prime

but the sample output says,
18 is not prime.

so, even with a correct algorithm, you will never get accepted, because the judge compares, your output with judges, character by character.

Good Luck!!
shamim
A great helper
Posts: 498
Joined: Mon Dec 30, 2002 10:10 am
Location: Bozeman, Montana, USA

Post by shamim »

PS

How about changing your name if you do not mind. :P :lol: :D

I mean same name causes loss of our uniqeness. :)
shamim(aiub)
New poster
Posts: 5
Joined: Wed Oct 22, 2003 3:29 am
Location: dhaka
Contact:

just reply

Post by shamim(aiub) »

i have solved the problem and got AC(without changing "isprime()").
there was some miskate.

to shamim,
should i change my ID?

shamim(aiub)
bery olivier
Learning poster
Posts: 90
Joined: Sat Feb 15, 2003 1:39 am
Location: Paris, France
Contact:

Post by bery olivier »

shamim wrote:PS

How about changing your name if you do not mind. :P :lol: :D

I mean same name causes loss of our uniqeness. :)
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.
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 Image AC at last Image
shamim
A great helper
Posts: 498
Joined: Mon Dec 30, 2002 10:10 am
Location: Bozeman, Montana, USA

Post by shamim »

To Shamim(aiub)
to shamim,
should i change my ID?
Well, maybe you could do something, since you have not made so many posts, you could delete your current account and register again.
Joseph Kurniawan
Experienced poster
Posts: 136
Joined: Tue Apr 01, 2003 6:59 am
Location: Jakarta, Indonesia

Post by Joseph Kurniawan »

I'm really really sorry for the false info. It seems my BC is broken. Now I've fixed it. :oops: :oops: :oops: :oops:
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.
Kamanashish
New poster
Posts: 10
Joined: Wed Dec 17, 2003 3:12 pm
Location: Dhaka
Contact:

10235 Why WA.

Post by Kamanashish »

CUT
Last edited by Kamanashish on Wed Mar 17, 2004 4:08 pm, edited 1 time in total.
Work hard.
sidky
New poster
Posts: 50
Joined: Wed Nov 06, 2002 1:37 pm
Location: Planet Earth, Universe
Contact:

Post by sidky »

http://online-judge.uva.es/board/viewtopic.php?t=2004

1 or 0 are not even prime. So, they can't be emirp
kiha
New poster
Posts: 37
Joined: Sat Dec 20, 2003 10:59 pm

Post by kiha »

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]
kiha
alu_mathics
Learning poster
Posts: 55
Joined: Sat Jan 24, 2004 9:30 pm
Location: Chittagong
Contact:

Post by alu_mathics »

An Emirp (Prime spelt backwards) is a Prime that gives you a different Prime when its digits are reversed.
So
11 is not emirp.
You can use seive method.This will help u a lot.
cuii e
Post Reply

Return to “Volume 102 (10200-10299)”