10235  Simply Emirp
Moderator: Board moderators

 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.
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

 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.
"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.
SIGABRT, problem 10235 Simply Emirp
Hi,
what could be the reason for the following message:
It seems as if the implementation could be sitedependent.
Could anybody please help?
what could be the reason for the following message:
I already searched the net for some information but that didn't help.Your program has died with signal 6 (SIGABRT). Meaning:
Abort signal from abort()
Before crash, it ran during 0.221 seconds.
It seems as if the implementation could be sitedependent.
Could anybody please help?
Re: SIGABRT, problem 10235 Simply Emirp
SIGABRT is an exception voluntarily generated by your program with a call to the abort() function.WR wrote:Hi,
what could be the reason for the following message:
I already searched the net for some information but that didn't help.Your program has died with signal 6 (SIGABRT). Meaning:
Abort signal from abort()
Before crash, it ran during 0.221 seconds.
It seems as if the implementation could be sitedependent.
Could anybody please help?
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
Unfortunately I only know a method: comment the second assert, submit, uncomment the second, comment the first, submit.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?
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
This is the message I received:
and this is the calling line:
with the intention to stop the program if n < 2 or n >= MAXPRIME.
Should work, shouldn't it?
Code: Select all
Your program has died with signal 6 (SIGABRT). Meaning:
Abort signal from abort()
Before crash, it ran during 2.824 seconds.
Code: Select all
assert((n > 1) && (n < MAXPRIME));
Should work, shouldn't it?
Yes, it should behave as expected...WR wrote:and this is the calling line:
with the intention to stop the program if n < 2 or n >= MAXPRIME.Code: Select all
assert((n > 1) && (n < MAXPRIME));
Should work, shouldn't it?
Ciao!!!
Claudio
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?
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.
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
[/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;
}
#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;
}
Last edited by nasty on Sat Jul 10, 2004 1:35 pm, edited 2 times in total.
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[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[(size1)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]
#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[(size1)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]