Page 11 of 13
Re: 406 - WA ...
Posted: Fri Dec 21, 2012 9:10 pm
by brianfry713
That looks correct but on ideone your code prints:
https://ideone.com/RFTlgB
Try modifying your code to handle this case correctly.
Re: 406 - WA ...
Posted: Sat Dec 22, 2012 1:41 am
by tommy5198
https://ideone.com/bEuxcb
i fix it but still WA ..><
Re: 406 - WA ...
Posted: Sat Dec 29, 2012 11:15 pm
by brianfry713
try input 999 59
Why TLE?
Posted: Sat Jan 12, 2013 9:08 pm
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;
}
Re: 406 - WA ...
Posted: Sun Jan 13, 2013 8:30 pm
by brianfry713
change line 30 to:
while(scanf("%d%d",&n,&m)==2)
406 - Prime Cuts WA
Posted: Fri Mar 29, 2013 2:19 pm
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 :
Re: 406 - Prime Cuts WA
Posted: Fri Mar 29, 2013 10:44 pm
by brianfry713
Try input 1000 1000
Re: 406 - Prime Cuts WA
Posted: Sat Mar 30, 2013 7:08 am
by 123321321
brianfry713 wrote:Try input 1000 1000
I have tried this case:
input:
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.
Re: 406 - Prime Cuts WA
Posted: Sat Mar 30, 2013 11:12 am
by shuvokr
123321321
1st for input 1000 1000 your code don't give any output in my Computer And
Try this input
May be it's Help you ....
Re: 406 - Prime Cuts WA
Posted: Sat Mar 30, 2013 11:38 am
by 123321321
shuvokr wrote:123321321
1st for input 1000 1000 your code don't give any output in my Computer And
Try this input
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~
Re: 406 - Prime Cuts WA
Posted: Wed Jul 03, 2013 10:03 am
by ashdboss
getting WA. need help.
Code deleted after getting AC
Re: 406 - Prime Cuts WA
Posted: Wed Jul 03, 2013 10:49 am
by t.tahasin
try this-
input:
13 6
correct output:
13 6: 1 2 3 5 7 11 13
Re: 406 - Prime Cuts WA
Posted: Wed Jul 03, 2013 10:59 am
by ashdboss
thanks
t.tahasin...got AC...

Re: 406 - Prime Cuts WA
Posted: Wed Jul 31, 2013 11:45 pm
by brianfry713
Be careful, there is a case where C > N in the judge's input.
Re: 406 - Prime Cuts WA
Posted: Thu Aug 15, 2013 1:23 pm
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;
}