Page 13 of 13

Re: 406 - Prime Cuts

Posted: Wed Sep 03, 2014 6:12 pm
by lighted
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++);

Re: 406 - Prime Cuts

Posted: Wed Sep 03, 2014 6:54 pm
by Shahidul.CSE
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

Re: 406 - Prime Cuts

Posted: Sat Sep 27, 2014 9:12 am
by fislam
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;
}

Re: 406 - Prime Cuts

Posted: Mon Sep 29, 2014 7:46 pm
by brianfry713
Each line of output should be followed by a blank line.

Re: INPUT NEEDED FOR 406

Posted: Tue Jan 27, 2015 3:06 pm
by mentalist_mbstu
getting wrong answer.. try several test case no error found... help plz...
my code-- http://pastebin.ubuntu.com/9896918/

Re: 406 - Prime Cuts

Posted: Tue Jan 27, 2015 9:18 pm
by brianfry713
It looks like you figured it out.

Re: 406 - Prime Cuts

Posted: Wed Jan 28, 2015 7:36 am
by mentalist_mbstu
i try all i/o of Debug as u suggested bt no error found...!!!!!!!!!!!! help bro

Re: 406 - Prime Cuts

Posted: Mon Feb 02, 2015 7:22 am
by mentalist_mbstu
?????????????? tell something :(