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.
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 :/
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.
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.
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...
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
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?
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.
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;
}
Last edited by nasty on Sat Jul 10, 2004 1:35 pm, edited 2 times in total.
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]