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

lighted
Guru
Posts: 585
Joined: Wed Jun 11, 2014 9:56 pm
Location: Kyrgyzstan, Bishkek

Re: 406 - Prime Cuts

Post by lighted » Wed Sep 03, 2014 6:12 pm

If you make your array prime global, you'll get RE. It is because of this line

Code: Select all

for(i=1;prime[i]<=n;i++);
Add

Code: Select all

for(i = 1; i <= k  &&  prime[i] <= n; i++);
A person who sees the good in things has good thoughts. And he who has good thoughts receives pleasure from life... Bediuzzaman

Shahidul.CSE
Experienced poster
Posts: 148
Joined: Sun Jul 13, 2014 4:32 am
Location: Rangpur, Bangladesh

Re: 406 - Prime Cuts

Post by Shahidul.CSE » Wed Sep 03, 2014 6:54 pm

lighted wrote:If you make your array prime global, you'll get RE. It is because of this line

Code: Select all

for(i=1;prime[i]<=n;i++);
Add

Code: Select all

for(i = 1; i <= k  &&  prime[i] <= n; i++);
Thanks, lighted!! Got Accepted !! :D :D :D
Md. Shahidul Islam
Dept. of CSE at Begum Rokeya University, Rangpur, Bangladesh
UVa id: http://uhunt.felix-halim.net/id/438420
My facebook account,
Email me: shahidul.cse.brur@gmail.com

fislam
New poster
Posts: 2
Joined: Fri Sep 19, 2014 4:45 am

Re: 406 - Prime Cuts

Post by fislam » Sat Sep 27, 2014 9:12 am

why wa ??

Code: Select all

#include<stdio.h>
#include<iostream>
#include<math.h>
#include<stdlib.h>
using namespace std;
void prime();
const int n_max = 1000;
int finalarr[n_max+1],getarr[175];
bool yprime[n_max+1];

void prime(){
  yprime[1] = true;
  for (int i = 2, e = static_cast<int>(sqrt(static_cast<double>(n_max)));i <= e; i++)
    if (!yprime[i]) {
      for (int j = i * i; j <= n_max; j += i)
        yprime[j] = true;
    }
}

int main()
{
    prime();
int i,j,aflag,n,t,s,nk,cont,cont1,a,blk,ii,b,lfg;

finalarr[1]=1;
finalarr[2]=2;
getarr[1]=1;
getarr[2]=2;
cont=2;
       for(i=3; i<=n_max; i=i+2)
        {
            finalarr[i]=cont;
             finalarr[i+1]=cont;
            if(!yprime[i]){
            {
                cont++;
                getarr[cont]=i;
                finalarr[i]=cont;
                    finalarr[i+1]=cont;
            }

        }
}
  int c,numprim,k,aa,bb;
    while(scanf("%d%d",&a,&b)==2){
            aa=a;
    bb=b;
          numprim=finalarr[a];
          if(b>=a)
          {
              printf("%d %d:",a,b);
              for(int i=1;i<=numprim;i++)
                printf(" %d",getarr[i]);
                printf("\n");
          }
        else if(numprim%2==1)
        {
            b=b*2-1;
    k=(numprim-b)/2;
    printf("%d %d:",aa,bb);
            for(int i=k+1;i<=k+b;i++)
                printf(" %d",getarr[i]);
                 printf("\n");
        }
        else if(numprim%2==0)
        {
             b=b*2;
    k=(numprim-b)/2;
     printf("%d %d:",aa,bb);
            for(int i=k+1;i<=k+b;i++)
                printf(" %d",getarr[i]);
                 printf("\n");
        }


}
return 0;
}

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

Re: 406 - Prime Cuts

Post by brianfry713 » Mon Sep 29, 2014 7:46 pm

Each line of output should be followed by a blank line.
Check input and AC output for thousands of problems on uDebug!

mentalist_mbstu
New poster
Posts: 12
Joined: Mon Nov 18, 2013 10:37 pm

Re: INPUT NEEDED FOR 406

Post by mentalist_mbstu » Tue Jan 27, 2015 3:06 pm

getting wrong answer.. try several test case no error found... help plz...
my code-- http://pastebin.ubuntu.com/9896918/

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

Re: 406 - Prime Cuts

Post by brianfry713 » Tue Jan 27, 2015 9:18 pm

It looks like you figured it out.
Check input and AC output for thousands of problems on uDebug!

mentalist_mbstu
New poster
Posts: 12
Joined: Mon Nov 18, 2013 10:37 pm

Re: 406 - Prime Cuts

Post by mentalist_mbstu » Wed Jan 28, 2015 7:36 am

i try all i/o of Debug as u suggested bt no error found...!!!!!!!!!!!! help bro
Last edited by mentalist_mbstu on Mon Feb 02, 2015 7:39 am, edited 4 times in total.

mentalist_mbstu
New poster
Posts: 12
Joined: Mon Nov 18, 2013 10:37 pm

Re: 406 - Prime Cuts

Post by mentalist_mbstu » Mon Feb 02, 2015 7:22 am

?????????????? tell something :(

Post Reply

Return to “Volume 4 (400-499)”