## 406 - Prime Cuts

Moderator: Board moderators

sohel
Guru
Posts: 856
Joined: Thu Jan 30, 2003 5:50 am
Location: New York

### Re: problem 406

shantanu18 wrote:i can't edit my post so can not delete my code
why can't you edit your post?

faiem
New poster
Posts: 14
Joined: Fri Aug 13, 2010 12:22 pm

### Output-406

Remember,
The Output should....
1 1
1 1: 1
(blank space is here)
21 2
21 2: 5 7 11

Now try......
Last edited by faiem on Fri Sep 03, 2010 7:16 am, edited 1 time in total.

faiem
New poster
Posts: 14
Joined: Fri Aug 13, 2010 12:22 pm

### Re: 406-WA

I found my problem.
The Output should....
10 2
10 2: 2 3 5

1 1
1 1: 1

my mistake is blank space between output....

faiem
New poster
Posts: 14
Joined: Fri Aug 13, 2010 12:22 pm

### Re: 406-WA

Now I got AC...

refat_ruet
New poster
Posts: 3
Joined: Fri Aug 20, 2010 10:24 am

### prime cut..help me...(406)

i am getting W...waiting 4 some suggation....

sohel
Guru
Posts: 856
Joined: Thu Jan 30, 2003 5:50 am
Location: New York

### Re: prime cut..help me...(406)

search the board first using the 'search option' located at the top-right. Don't create a new thread for a problem that already exists, make your post in an existing one.

anjanpstu
New poster
Posts: 7
Joined: Thu Apr 07, 2011 8:40 am

### I am always getting WA but I cannot locate my problem

Code: Select all

``````#include<stdio.h>
#include<math.h>
int main()
{
int sr[169];int count=2;int flag=1;int i,b;int n,m;int count1=0;int even,odd;int even1,odd1;int even2,odd2;int even3,odd3;

sr[0]=1;sr[1]=2;sr[2]=3;sr[3]=5;
for( i=5;i<=1000;i+=2)
{
int s=(int)sqrt(i);
for(int j=2;j<=s;j++)
{
if(i%j!=0)flag=0;
else
{
flag=1;
break;
}
}
if(flag==0)
{
count=count+1;
sr[count]=i;
}
}

while((scanf("%d %d",&n,&m))==2)
{
count1=0;
int k=0;
while(sr[k]<=n)
{
count1=count1+1;
k++;
}

printf(" %d %d:",n,m);
if(count1%2==0)
{
even=m*2;
even1=(count1-even);
even2=even1/2;
even3=even2+even;

if(even>=count1)
{
int k1=0;
while(sr[k1]<=n)
{
printf(" %d",sr[k1]);
k1++;
}

}
else if(even<count1)
{
for(int i=even2;i<even3;i++)
printf(" %d",sr[i]);
}

}
else if(count1%2!=0)
{
odd=(m*2)-1;
odd1=(count1-odd);
odd2=odd1/2;
odd3=odd2+odd;
if(odd>=count1)
{
int k1=0;
while(sr[k1]<=n)
{
printf(" %d",sr[k1]);
k1++;
}

}
else if(odd<count1)
{
for(int i=odd2;i<odd3;i++)
printf(" %d",sr[i]);

}

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

}
``````

New poster
Posts: 16
Joined: Thu Apr 28, 2011 10:48 pm

### 406-prime cuts WA why !!!!!!!!!!!!

here is my implementation using java

Code: Select all

``Accepte...d``

New poster
Posts: 16
Joined: Thu Apr 28, 2011 10:48 pm

### 406 - prime cuts ... WA ?!?!??!!?!?!??!

i tested my code alot of times and i always find the expected answer ...
here is my implementation using java

Code: Select all

``Accepted``

Asma_ju
New poster
Posts: 4
Joined: Sat Jun 11, 2011 9:20 am

### Re: 406 - Prime Cuts

lnr wrote:Try this case:
Input:

Code: Select all

``````100 51
1000 1000
954 1
``````
Output:

Code: Select all

``````100 51: 1 2 3 5 7 11 13 17 19 23 29 31 37 41 43 47 53 59 61 67 71 73 79 83 89 97

1000 1000: 1 2 3 5 7 11 13 17 19 23 29 31 37 41 43 47 53 59 61 67 71 73 79 83 89 97 101 103 107 109 113 127 131 137 139 149 151 157 163 167 173 179 181 191 193 197 199 211 223 227 229 233 239 241 251 257 263 269 271 277 281 283 293 307 311 313 317 331 337 347 349 353 359 367 373 379 383 389 397 401 409 419 421 431 433 439 443 449 457 461 463 467 479 487 491 499 503 509 521 523 541 547 557 563 569 571 577 587 593 599 601 607 613 617 619 631 641 643 647 653 659 661 673 677 683 691 701 709 719 727 733 739 743 751 757 761 769 773 787 797 809 811 821 823 827 829 839 853 857 859 863 877 881 883 887 907 911 919 929 937 941 947 953 967 971 977 983 991 997

954 1: 419

``````
Hope it helps.
But i don't know how to remove the space before any digit when the output is too long and will be printed in newline.Can anyone please give any idea?

abhiramn
New poster
Posts: 29
Joined: Sat May 26, 2007 7:54 pm

### Re: problem 406

Hello,

I don't know why, but I seem to be getting WA for my code. Here it is:

Code: Select all

``Accepted  :D ``
^^^^ My problem was that I was printing a blank line only between outputs. It clearly states in the problem that a blank line must be there after all outputs, even if it is just one output. People, please be careful about this

Is it possible that we get an input of N > 1000?

permalia
New poster
Posts: 1
Joined: Fri Jul 06, 2012 6:30 am
Contact:

### Re: problem 406

I am don't getting this problem.
Sample Input

21 2
18 2
18 18
100 7
Sample Output

21 2: 5 7 11

18 2: 3 5 7 11

18 18: 1 2 3 5 7 11 13 17

100 7: 13 17 19 23 29 31 37 41 43 47 53 59 61 67

i really don't understand the question.would somebody like to help me to get it out.

tommy5198
New poster
Posts: 3
Joined: Thu Dec 20, 2012 4:45 pm

### 406 - WA ...

plz help me .. new line after output dont work ><
my code:

Code: Select all

``````#include<iostream>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<cctype>
#include<string>
#include<cmath>
using namespace std;

bool isprime(int t){
if(t==2||t==3)
return true;
else if(t%2==0||t%3==0)
return false;
int s=sqrt(t);
for(int i=2;i<=s;i++)
if(t%i==0)
return false;
return true;
}

int main(){

int a,b;
int prime[1000],c=1;
prime[0]=1;
for(int i=2;i<1001;i++){
if(isprime(i)){
prime[c]=i;
c++;
}
}
while(cin>>a>>b){
for(c=0;c<1000;c++)
if(prime[c]>a)
break;

cout<<a<<" "<<b<<":";
if(c%2){
if(2*b-1>c)
for(int i=0;prime[i]<=a;i++)
cout<<" "<<prime[i];
else
for(int i=c/2-b+1;i<=c/2+b-1;i++)
cout<<" "<<prime[i];
}else{
if(2*b>c)
for(int i=0;prime[i]<=a;i++)
cout<<" "<<prime[i];
else
for(int i=c/2-b;i<=c/2+b-1;i++)
cout<<" "<<prime[i];
}
cout<<"\n\n";
}
return 0;
}
``````

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

### Re: 406 - WA ...

Try input 1000 1000
Check input and AC output for thousands of problems on uDebug!

tommy5198
New poster
Posts: 3
Joined: Thu Dec 20, 2012 4:45 pm

### Re: 406 - WA ...

input:

Code: Select all

``1000 1000``
output:

Code: Select all

``````1000 1000: 1 2 3 5 7 11 13 17 19 23 29 31 37 41 43 47 53 59 61 67 71 73 79 83 89 97 101 103 107 109 113 127 131 137 139 149 151 157 163 167 173 179 181 191 193 197 199 211 223 227 229 233 239 241 251 257 263 269 271 277 281 283 293 307 311 313 317 331 337 347 349 353 359 367 373 379 383 389 397 401 409 419 421 431 433 439 443 449 457 461 463 467 479 487 491 499 503 509 521 523 541 547 557 563 569 571 577 587 593 599 601 607 613 617 619 631 641 643 647 653 659 661 673 677 683 691 701 709 719 727 733 739 743 751 757 761 769 773 787 797 809 811 821 823 827 829 839 853 857 859 863 877 881 883 887 907 911 919 929 937 941 947 953 967 971 977 983 991 997

``````
is it right?