406 - Prime Cuts

All about problems in Volume 4. If there is a thread about your problem, please use it. If not, create one with its number in the subject.

Moderator: Board moderators

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

Re: problem 406

Post by sohel » Tue Jul 27, 2010 12:32 pm

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

Post by faiem » Thu Sep 02, 2010 12:43 am

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

Post by faiem » Thu Sep 02, 2010 7:28 am

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

Post by faiem » Thu Sep 02, 2010 7:30 am

Now I got AC...

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

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

Post by refat_ruet » Fri Sep 03, 2010 9:16 pm

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

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

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

Post by sohel » Sat Sep 04, 2010 9:09 am

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

Post by anjanpstu » Sun Apr 17, 2011 1:26 pm

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;

  }

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

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

Post by Ahmad » Sun May 01, 2011 1:26 pm

i think the problem is about the i/o ... so please help me cuz i'm not able to figure it out
here is my implementation using java

Code: Select all

Accepte...d

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

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

Post by Ahmad » Sun May 01, 2011 3:28 pm

i think the problem is about the i/o ... so please help me cuz i'm not able to figure it out
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

Post by Asma_ju » Tue Oct 04, 2011 5:19 pm

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

Post by abhiramn » Fri Jul 06, 2012 4:43 am

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
Location: Dhaka,Bangladesh
Contact:

Re: problem 406

Post by permalia » Fri Jul 06, 2012 6:51 am

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

Post by tommy5198 » Thu Dec 20, 2012 4:50 pm

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

Post by brianfry713 » Thu Dec 20, 2012 9:05 pm

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

Post by tommy5198 » Fri Dec 21, 2012 3:46 pm

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?

Post Reply

Return to “Volume 4 (400-499)”