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

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

Re: 406 - WA ...

Post by brianfry713 »

That looks correct but on ideone your code prints:
https://ideone.com/RFTlgB
Try modifying your code to handle this case correctly.
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 »

https://ideone.com/bEuxcb

i fix it but still WA ..><
brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 406 - WA ...

Post by brianfry713 »

try input 999 59
Check input and AC output for thousands of problems on uDebug!
Mahabub Khan
New poster
Posts: 5
Joined: Sun Apr 08, 2012 5:36 pm

Why TLE?

Post by Mahabub Khan »

#include<cstdio>
#include<cmath>
#define max 1004

int prime[max+1];
int twin[max];

void sieve()
{
int i,j;
for(i=2; i <= max; i++)
prime = 1;
for(i=2; i <= sqrt(max);)
{
for(j = 2*i; j <= max; j += i)
{
prime[j]=0;
}
i++;
for(; !prime; i++);
}
prime[1] = 1;
prime[2] = 1;
prime[0] = 0;
}
int main()
{
sieve();
int n,m,p = 0,k;
while(scanf("%d%d",&n,&m))
{
k = p = 0;
printf("%d %d: ",n,m);
for(int i = 1; i <= n; i++)
{
if(prime == 1)
{
k++;
twin[++p] = i;
}
}
if(m*2 >= k)
{
for(int r = 1; r <= n; r++)
{
if(prime[r] == 1)
printf("%d ",r);
}
}
else if(k % 2 == 0)
{
for(int i = k/2-m+1,j = 0; j < m*2; i++)
{

printf("%d ",twin);
j++;
}
}
else if(k % 2 != 0)
{
for(int i = k/2-m+2,j = 0; j < m*2-1; i++)
{

printf("%d ",twin);
j++;

}
}
printf("\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 »

change line 30 to:
while(scanf("%d%d",&n,&m)==2)
Check input and AC output for thousands of problems on uDebug!
123321321
New poster
Posts: 4
Joined: Fri Mar 29, 2013 2:13 pm

406 - Prime Cuts WA

Post by 123321321 »

I have got many WAs with this problem 406.....
I test many test cases , but I still get WA lol...
Please help me :(

The following is my C++ code :

Code: Select all

The deleted code is a AC code!
Last edited by 123321321 on Sat Mar 30, 2013 11:34 am, edited 2 times in total.
brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 406 - Prime Cuts WA

Post by brianfry713 »

Try input 1000 1000
Check input and AC output for thousands of problems on uDebug!
123321321
New poster
Posts: 4
Joined: Fri Mar 29, 2013 2:13 pm

Re: 406 - Prime Cuts WA

Post by 123321321 »

brianfry713 wrote:Try input 1000 1000
I have tried this case:

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

I think this case is correct.
shuvokr
Learning poster
Posts: 66
Joined: Tue Oct 02, 2012 8:16 pm
Location: Bangladesh

Re: 406 - Prime Cuts WA

Post by shuvokr »

123321321
1st for input 1000 1000 your code don't give any output in my Computer And
Try this input

Code: Select all

997 997
997 991
May be it's Help you ....

Code: Select all

enjoying life ..... 
123321321
New poster
Posts: 4
Joined: Fri Mar 29, 2013 2:13 pm

Re: 406 - Prime Cuts WA

Post by 123321321 »

shuvokr wrote:123321321
1st for input 1000 1000 your code don't give any output in my Computer And
Try this input

Code: Select all

997 997
997 991
May be it's Help you ....
Thanks a lot! I finally get AC!
The main problem is that I originally use IDE code block to write the c++ code. In the IDE, input "1000 1000" can correctly produce output. Then I copy the code to VS 2010, The output is empty !! It's like what you say! So I debug it on VS2010~
ashdboss
New poster
Posts: 16
Joined: Fri May 17, 2013 8:59 am

Re: 406 - Prime Cuts WA

Post by ashdboss »

getting WA. need help.
Code deleted after getting AC
Last edited by ashdboss on Wed Jul 03, 2013 10:59 am, edited 1 time in total.
t.tahasin
New poster
Posts: 38
Joined: Tue May 28, 2013 11:21 pm

Re: 406 - Prime Cuts WA

Post by t.tahasin »

try this-
input:
13 6
correct output:
13 6: 1 2 3 5 7 11 13
ashdboss
New poster
Posts: 16
Joined: Fri May 17, 2013 8:59 am

Re: 406 - Prime Cuts WA

Post by ashdboss »

thanks t.tahasin...got AC... :)
brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 406 - Prime Cuts WA

Post by brianfry713 »

Be careful, there is a case where C > N in the judge's input.
Check input and AC output for thousands of problems on uDebug!
xplosive
New poster
Posts: 4
Joined: Sat Aug 03, 2013 2:49 pm

Re: 406 - Prime Cuts WA

Post by xplosive »

what's wrong ... i get many wa..

Code: Select all

//406 - Prime Cuts

#include <iostream>
#include <cstdio>
using namespace std;

int is_prime(int n);

int main()
{
    //freopen("uvainput.txt", "r", stdin);
    //freopen("uvaoutput.txt", "w", stdout);

    int i,j,n,c,l,show,start,k=0;
    int a[10000];

    while(scanf("%d %d",&n,&c)==2)
    {
        if(k)
            printf("\n");

        j=0;
        for(i=1; i<=n; i++)
        {
            if(is_prime(i))
            {
                a[j]=i;
                j++;
            }
        }
        l=j;

        if(l%2==0)
            show=c*2;
        else
            show=(c*2)-1;

        start=(l-show)/2;

        printf("%d %d: ",n,c);

        if(show>l)
        {
            for(i=0; i<l; i++)
            {
                printf("%d ",a[i]);
            }
        }
        else
        {
            for(i=start,j=0; j<show; i++,j++)
            {
                printf("%d ",a[i]);
            }

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

    return 0;
}

int is_prime(int n)
{
    int d;
    if(n<1)
        return 0;
    if(n==1)            //1 considerd as prime
        return 1;

    for (d=2; d*d<=n; d++)
    {
        if(n%d==0)
            return 0;
    }
    return 1;

}


Post Reply

Return to “Volume 4 (400-499)”