## 10235 - Simply Emirp

Moderator: Board moderators

kiha
New poster
Posts: 37
Joined: Sat Dec 20, 2003 10:59 pm
Excuse me,

My program gives output "11 is prime" not "11 is emirp". Have you tested it ? It's written in the line :

[pascal]
if (og = g) and (n) then nn:=false;
[/pascal]

See any other mistakes? With regards
kiha

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

100000 is not prime.
999999 is not prime.
99999 is not prime.
123 is not prime.
321 is not prime.
1 is not prime.
2 is prime.
3 is prime.
4 is not prime.
7 is prime.
5 is prime.
13 is emirp.
111 is not prime.
1111 is not prime.
22222 is not prime.
5555 is not prime.
867 is not prime.
3254 is not prime.
123511 is not prime.
89 is prime.
98 is not prime.
70 is not prime.
7 is prime.
10 is not prime.
1 is not prime.
cuii e

kiha
New poster
Posts: 37
Joined: Sat Dec 20, 2003 10:59 pm
Shit, still WA

Look, I doubt if some your outputs are correct, for example:
I think that :
3254 is 'emirp' not 'not prime'
123511 is 'emirp' not 'not prime'
According to your output, '89 is prime'. So why
'98 is not prime' ? Shouldn't it be emirp :/
kiha

Guru
Posts: 724
Joined: Wed Dec 19, 2001 2:00 am
Location: Germany
It seems you didn't understand the problem description.
"An Emirp (Prime spelt backwards) is a Prime that gives you a different Prime when its digits are reversed"
The "Prime spelt backwards" means, that if you reverse the word prime, you get emirp, it doesn't mean, a emirp is a number that is prime if spelt backwards. So for clarity, omit the words in parentheses and read:
"An Emirp is a Prime that gives you a different Prime when its digits are reversed". I hope this is clear to you now.

technobug
Learning poster
Posts: 88
Joined: Sat Nov 15, 2003 6:41 pm
Location: Brasilien
Contact:
just for ther records

an example given at this page doesnt fit in the correct interval for the problem.... long int (C) shall be enough for the judge but not for the case given on this page.

WR
Experienced poster
Posts: 145
Joined: Thu Nov 27, 2003 9:46 am

### SIGABRT, problem 10235 Simply Emirp

Hi,

what could be the reason for the following message:
Your program has died with signal 6 (SIGABRT). Meaning:

Abort signal from abort()

Before crash, it ran during 0.221 seconds.
I already searched the net for some information but that didn't help.

It seems as if the implementation could be site-dependent.

CDiMa
Experienced poster
Posts: 214
Joined: Fri Oct 17, 2003 5:49 pm
Location: Genova

### Re: SIGABRT, problem 10235 Simply Emirp

WR wrote:Hi,

what could be the reason for the following message:
Your program has died with signal 6 (SIGABRT). Meaning:

Abort signal from abort()

Before crash, it ran during 0.221 seconds.
I already searched the net for some information but that didn't help.

It seems as if the implementation could be site-dependent.

SIGABRT is an exception voluntarily generated by your program with a call to the abort() function.
This usually is wrapped in the assert() function/macro.

So at runtime your program stumbles on an assert that isn't satisfied and aborts...

Ciao!!!

Claudio

WR
Experienced poster
Posts: 145
Joined: Thu Nov 27, 2003 9:46 am
Thanks Claudio,

in fact there are two calls of assert(...) in that program. Obviously one of them causes that error. Is there a way to determine which?

As I used assert to check the problem's input data this now is the wrong thread, I switch to 10235. No hope to get an answer, though. CDiMa
Experienced poster
Posts: 214
Joined: Fri Oct 17, 2003 5:49 pm
Location: Genova
WR wrote:in fact there are two calls of assert(...) in that program. Obviously one of them causes that error. Is there a way to determine which?
Unfortunately I only know a method: comment the second assert, submit, uncomment the second, comment the first, submit.
Make sure you get your asserts right. I've done the stupid error to reverse the check the first time I used asserts and it took a while to figure out why my prog alway aborted Ciao!!!

Claudio

WR
Experienced poster
Posts: 145
Joined: Thu Nov 27, 2003 9:46 am
This is the message I received:

Code: Select all

``````Your program has died with signal 6 (SIGABRT). Meaning:

Abort signal from abort()

Before crash, it ran during 2.824 seconds.``````
and this is the calling line:

Code: Select all

``assert((n > 1) && (n < MAXPRIME));``
with the intention to stop the program if n < 2 or n >= MAXPRIME.

Should work, shouldn't it?

CDiMa
Experienced poster
Posts: 214
Joined: Fri Oct 17, 2003 5:49 pm
Location: Genova
WR wrote:and this is the calling line:

Code: Select all

``assert((n > 1) && (n < MAXPRIME));``
with the intention to stop the program if n < 2 or n >= MAXPRIME.

Should work, shouldn't it?
Yes, it should behave as expected...

Ciao!!!

Claudio

misof
A great helper
Posts: 430
Joined: Wed Jun 09, 2004 1:31 pm
Check the rest of your code. Especially: Does reading input work as you want it to? Can the assert fail at the end of the input? Is the value MAXPRIME large enough? Is it really large enough? (Note that n doesn't have to be prime, the name MAXPRIME is at least misleading!) Are you sure that the value of n cannot be overwritten due to a bug?

WR
Experienced poster
Posts: 145
Joined: Thu Nov 27, 2003 9:46 am

the program has already been accepted. It was the reverse function that caused the crash. I haven't found the reason yet, though. Reversing the digits directly didn't work, a temporary char variable and sscanf did work. It made no difference whatsoever on my PC, so I'll probably never find the reason.

nasty
New poster
Posts: 4
Joined: Sat Jul 10, 2004 11:27 am
Location: pakistan

### 10235 help me out this code is not submitting on acm site

[/cpp]
#include<iostream>

using namespace std;

int check(int);
void separate( int );
bool prime(int,int);
int power(int,int);
int array;
int q;

int main()
{
int s= -1;
int z =0;
int i =0;
while(cin>>q[i])
{

if(q[i]<1000000 && q[i] > 0)
{
i++;
}

}
int w=0;
for(;w<i;w++)
{
s = q[w];
int k = s/4;
bool f = prime(s,k);
if(f == true)
{
separate(s);
int temp = check(s);
k = temp/2;
f = prime(temp,k);
if(f == true)
{
cout<<s<<" is emirp."<<endl;
}
else
{
cout<<s<<" is prime."<<endl;
}
}

else
{
cout<<s<<" is not prime."<<endl;
}
}
return 0;
}
int check(int s)
{
int temp = 0;
int i =0 ;
for(i =0 ;i < 10 ;i++)
{
array[i] = power(s,i);
temp += array[i];
}
return temp;
}
void separate( int i)
{
int t=0;
int t1,t2,t3;
t3 = i;
int j=0;
for(j;j<10;j++)
{
t1 = i%10;
array[j] = t1;
t2 = i/10;
if(t2<10)
{
j++;
array[j] = t2;
break;
}
else
{
i = t2;
}
}
int temparray = {-1};
int y =0;
int k =j;
for( k;k>=0;k--)
{
temparray[y] = array[k];
y++;
}
y =0;
for(k=0;k<=j;k++)
{
array[k] = temparray[y];
y++;
}
}

bool prime(int s, int k)
{
int y = 2;
bool f = true ;
for(int i = 2;i<s;i++)
{
if(s%i == 0)
{
f = false;
break;
}
}
if(s ==1)
{
f = false;

}
if(f == true)
{
//cout<<" prime No"<<endl;
return f;
}
else
{
//cout<<"Not a prime No"<<endl;
return f;
}
}

int power(int s, int i)
{
int t=0;
int temp = 1;
while(t != i)
{
temp = temp * 10;
t++;
}
temp = array[i] * temp;
return temp;

}
Last edited by nasty on Sat Jul 10, 2004 1:35 pm, edited 2 times in total.

nasty
New poster
Posts: 4
Joined: Sat Jul 10, 2004 11:27 am
Location: pakistan

### 10235 help me to reduce the time limit. plzzzzzzzzzz

[cpp]
#include<iostream>

using namespace std;

int check(int);
void separate( int);
bool prime(int);
int power(int,int);
int calsize(int s);
int array;
int q;
int size;

int main()
{
int s= -1;
int z =0;
int i =0;
while(cin>>q[i])
{
i++;

}
int w=0;
for(;w<i;w++)
{
s = q[w];

bool f = prime(s);
if(f == true)
{
size = calsize(s);
separate(s);
int temp = check(s);
f = prime(temp);
if(f == true)
{
cout<<s<<" is emirp."<<endl;
}
else
{
cout<<s<<" is prime."<<endl;
}
}

else
{
cout<<s<<" is not prime."<<endl;
}
}
return 0;
}
int check(int s)
{
int t = 0;
for(int i = 0;i<size;i++)
{
t += power(array[i],i);
}
return t;
}
void separate( int input)
{
int temp,temp1=0;
for(int i=0;i<size;i++)
{
temp = input % 10;
temp1 = input / 10;
input = temp1;
array[(size-1)-i] = temp;

}

}

bool prime(int s)
{
int y = 2;
bool f = true ;
for(int i = 2;i<s;i++)
{
if(s%i == 0)
{
f = false;
break;
}
}
if(s ==1)
{
f = false;

}
if(f == true)
{
//cout<<" prime No"<<endl;
return f;
}
else
{
//cout<<"Not a prime No"<<endl;
return f;
}
}

int power(int s, int i)
{
int t=0;
int temp = 1;
while(t != i)
{
temp = temp * 10;
t++;
}
temp = array[i] * temp;
return temp;

}

int calsize(int s)
{
int siz =0;
int t,t1=0;
bool ch = true;
while(ch)
{
t = s % 10;
t1 = s / 10;
s = t1;
siz++;
if(s <= 0)
ch = false;
}
return siz;
}
[/cpp]