Page 7 of 13

### 406---ALL PE!!!!!!!plz Help

Posted: Wed Jan 10, 2007 10:25 am
hi,

For the problem 406 (prime cuts) I simply printed 2 new line after each output :

My output format is like this:

Code: Select all

``````print(n*c:*);
print(list_of_prime_no*);
print(\n\n);
``````
here '*' represents the space (' ')

But I am constantly getting PE.

I have also tried like:

Code: Select all

``````Print 2 new lines after each case EXCEPT the LAST ONE.
but again its a PE.
``````
Can someone who had an ACC please tell me the correct output format precisely??????? I badly need this!

### 406 WA why?>"<

Posted: Thu Feb 01, 2007 2:43 pm
Here is my code

Code: Select all

``````#include <iostream>
#include <cmath>
using namespace std;

int primejudge (int n);

int main(){
int n , c;
while ((cin >> n >> c) && n >=1 && n <= 1000 && c >= 1 && c <= n){
if (n == 1){
prime = 1;
}
else if (n == 2){
prime = 1;
prime = 2;
}
else if (n == 3 || n == 4){
prime = 1;
prime = 2;
prime = 3;
}
else{
prime = 1;
prime = 2;
prime = 3;
for (int i = 0 ; (6 * i + 5) <= n ; i ++){
if (primejudge (6 * i + 5)){
prime[primeaddress] = 6 * i + 5;
}
if ((6 * i + 7) <= n && primejudge (6 * i + 7)){
prime[primeaddress] = 6 * i + 7;
}
}
}

if ((c - 1) <= primeaddress / 2 && primeaddress % 2 == 1){
cout << n << " " << c << " :";
for (int i = primeaddress / 2 - (c - 1) ; i <= primeaddress / 2 + (c - 1) ; i ++){
cout << " " << prime[i];
}
}
else if (c <= primeaddress / 2 && primeaddress % 2 == 0){
cout << n << " " << c << " :";
for (int i = primeaddress / 2  - c ; i <= primeaddress / 2 + c - 1 ; i ++){
cout << " " << prime[i];
}
}
else{
cout << n << " " << c << " :";
for (int i = 0 ; i < primeaddress ; i ++){
cout << " " << prime[i];
}
}
cout << endl << endl;
}
return 0;
}

int primejudge (int n){
for (int i = 2 ; i <= sqrt(n) ; i ++){
if (n % i == 0){
return 0;
}
}
return 1;
}``````
I have tried all the inputs, but still get WA.
Why? >""<

Posted: Sun Feb 04, 2007 6:51 am
after I change the ninth line in my code

Code: Select all

``while ((cin >> n >> c) && n >=1 && n <= 1000 && c >= 1 && c <= n)``
c <= n into c <= 1000
I have got AC.

Posted: Sun Feb 04, 2007 7:02 am
If you got AC, remove your code plz.. Posted: Thu Mar 22, 2007 11:11 am
hi!

AC Output format is:

n*c:*a*b*c*d#
#
n*c:*a*b*c*d#
#
n*c:*a*b*c*d#
#

But ur one may be:

n*c:*a*b*c*d*#
#
n*c:*a*b*c*d*#
#
n*c:*a*b*c*d*#
#

Posted: Fri Mar 23, 2007 8:07 am
Hi,

I think your output section is not right.

print(n*c:*);
print(list_of_prime_no*);
print(\n\n);
print(n*c:no space);
print(*list_of_prime_no);
print(\n\n);

Thanks.
ABDULLAH

Posted: Sun Mar 25, 2007 10:35 am
there should be two blank line after each case output printf("%ld %ld:",num,c);
for(i=start;i<=end;i++)
printf(" %d",prime);
printf("\n\n");

may be it works for u

### 406 NEED HELP

Posted: Tue May 22, 2007 12:21 pm
Here is my Code. I have been tired seeing WA. Can anyone find the BUG ? Thanx In advance.

#include<stdio.h>
#include<math.h>

int a,j,m,k=0,i,n,c1,c2,flag2,prime,flag,count,left,right;
int main()

{

while(scanf("%d %d",&n,&c1)==2)
{

printf("%d %d: ",n,c1);
if((n < 1 || n > 1000) || (c1 < 1 || c1 > n))
{
printf("\n\n");
continue;
}
for(i=0;i<=n+1;i++)

flag=1;flag2 = 0;
m=sqrt(n);
prime = 1;

for(i=2;i<=m;i++)
{
if (flag==1)
{
for(j=i+i;j<=n;j+=i)
flag[j]=0;
}
}

for(i=2,k=2,count=0;i<=n+1; i++)

{
if (flag==1)

{
prime[k++]=i;
count++;

}

}

if(count%2==0)
{
c2 = c1*2;

if (c2>=count)
{
for (i=1;i<=count;i++)
{
printf("%d ",prime);
}
flag2 = 1;

}

if(flag2!=1)
{
left = count/2 - c1 + 1;
right = count/2 + 1 + c1 - 1;

for (i=left;i<=right;i++)
printf("%d ",prime);

}
printf("\n\n");
}

if((flag2==0)&&(count%2!=0))
{
c2 = c1*2 -1 ;

if (c2>=count)
{
for (i=1;i<=count;i++)
{
printf("%d ",prime);
}
flag2 = 1;

}
if(flag2!=1)
{
left = (count+1)/2 - (c2- 1)/2;
right = (count+1)/2 + (c2- 1)/2;

for (i=left;i<=right;i++)
printf("%d ",prime);
}
printf("\n\n");
}
}

return 0;
}    Posted: Tue May 22, 2007 5:34 pm
Search the board first. Don't open a new thread if there is one already. And use code tags to post a code.

### 406 what's the prob with WA

Posted: Wed May 23, 2007 9:57 am

Code: Select all

``````#include<stdio.h>
#include<math.h>
#define size 1004
#define true 1
#define false 0

int main()
{
int a,b[size],m=0,i,j,k=0,t,p[size],prime[size];
int s;
p=false; p=true;

for(i=2; i<=size; i++)
p[i]=true;

s=sqrt(size);

for(i=2; i<=s; i++)
{
if(p[i]==true)
for(j=i+i; j<=size; j=j+i)
p[j]=false;
}

for(i=0; i<=size; i++)
{
if(p[i]==true)
{
prime[m]=i;
//printf("%d ",i);
m++;
}
}

while((scanf("%d %d",&a,&m))==2)
{
if(!((a>=1 && a<=1000) && (m>=1 && m<=a)))
break;

printf("%d %d: ",a,m);

k=0;
for(i=1; i<a; i++)
{
if(p[i]==true)
{
b[k]=i;
k++;
}

}

if(m*2>=a)for(i=0;i<k;i++)printf("%d ",b[i]);
else if(k/2-m<0 && k/2+m>k) for(i=0;i<k;i++)printf("%d ",b[i]);

else
{
if(k%2==0)
for(i=k/2-m;i<k/2+m;i++)printf("%d ",b[i]);

else for(i=k/2-m+1;i<k/2+m;i++)printf("%d ",b[i]);
}
printf("\n\n");
}
return 0;
}``````

Posted: Wed May 23, 2007 8:40 pm
Search the board first. Don't open a new thread if there is one already.

Posted: Sat Jun 09, 2007 10:41 am
hi everybody ..i think i am really dumb and i could not understand this problem after reading many times . i have some confusion kindly help me.

for input 1
21 2 prime numbers between 1 and 21 is 1 2 3 5 7 11 13 17 19 . therer are 9 (odd) prime numbers in the list so we need to print (2*2 -1) =3 prime numbers from the middle of the list.
now my confusion is that middle of list will 4th elment (9/2 ) or fifth element .
As i studied in statistics if number of elements are odd in list then middle element will be (n/2)+1th term so middle term should be fifth and output should be printed from 5th element .
so output should be like this 7 11 13 .

now if there are even numbers in the list then we have two middle of the list
1) n/2th term
2) (n/2)+1 th term

so for second input
18 2
prime list 1 2 3 5 7 11 13 17 .
8 prime numbers so we have to print 4 term from middle of list and middle term will be 4th and 5th and if we print from 4th term
then output should be 5 7 11 13
and if we print from 5th term then output should be
7 11 13 17

kindly help me ...

Posted: Sat Jun 09, 2007 5:43 pm
mukeshtiwari wrote:for input 1
21 2 prime numbers between 1 and 21 is 1 2 3 5 7 11 13 17 19 . therer are 9 (odd) prime numbers in the list so we need to print (2*2 -1) =3 prime numbers from the middle of the list.
now my confusion is that middle of list will 4th elment (9/2 ) or fifth element .
As i studied in statistics if number of elements are odd in list then middle element will be (n/2)+1th term so middle term should be fifth and output should be printed from 5th element .
so output should be like this 7 11 13 .
No no no. 7 is the median, and three numbers should be printed. So, print one number from the left of 7 and one from the right. So, 5 7 11 should be the output.

If you want to print 5 numbers then it should be 3 5 7 11 13. And similar approach should be applied when there are even number of numbers.

Hope these help.

### What is the PE in my p406

Posted: Thu Jul 12, 2007 5:01 pm
Plz help me to find out the PE.

Code: Select all

``````#include<stdio.h>
int isprime(int x)
{
int i=2;
while(i*i<=x)
{
if(x%i==0)
return 0;
i++;
}
return 1;
}

void main()
{
int k=0,i,a,n,c=0;
while(scanf("%d %d",&n, &c)!=EOF && (n&&c))
{
printf("%d %d:",n,c);
k=0;
for(i=1; i<=n; i++)
if(isprime(i))
a[k++]=i;
if(c>k/2)
i=0;
else
if(k%2==0)
i=(k/2)-c;
else
i=(k/2)-(c-1);
for( ; i<(k/2)+c; i++)
{
if(i>=k)
break;
printf(" %d ",a[i]);
}
printf("\n\n");
}
}
``````
THAKS TO ALL.

Posted: Thu Jul 12, 2007 5:12 pm