Page 5 of 11

Posted: Tue Mar 09, 2004 8:55 pm
by kiha
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

Posted: Wed Mar 10, 2004 12:31 am
by alu_mathics
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.

Posted: Wed Mar 10, 2004 10:31 pm
by kiha
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 :/

Posted: Wed Mar 10, 2004 10:40 pm
by Adrian Kuegel
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.

Posted: Mon Apr 05, 2004 4:56 am
by technobug
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.

SIGABRT, problem 10235 Simply Emirp

Posted: Fri Jun 11, 2004 12:49 pm
by WR
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.

Could anybody please help?

Re: SIGABRT, problem 10235 Simply Emirp

Posted: Fri Jun 11, 2004 1:22 pm
by CDiMa
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.

Could anybody please help?
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

Posted: Mon Jun 14, 2004 7:52 am
by WR
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. :cry:

Posted: Mon Jun 14, 2004 10:34 am
by CDiMa
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

Posted: Mon Jun 14, 2004 11:53 am
by WR
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?

Posted: Mon Jun 14, 2004 1:27 pm
by CDiMa
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

Posted: Fri Jun 25, 2004 12:25 pm
by misof
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?

Posted: Mon Jun 28, 2004 7:47 am
by WR
Thanks for the reply Misof,

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.

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

Posted: Sat Jul 10, 2004 11:37 am
by nasty
[/cpp]
#include<iostream>

using namespace std;


int check(int);
void separate( int );
bool prime(int,int);
int power(int,int);
int readtext();
int array[8];
int q[1000000];

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[100] = {-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;

}

10235 help me to reduce the time limit. plzzzzzzzzzz

Posted: Sat Jul 10, 2004 3:45 pm
by nasty
[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[8];
int q[10000];
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]