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
Riyad
Experienced poster
Posts: 131
Joined: Thu Aug 14, 2003 10:23 pm
Location: BUET
Contact:

hey .........

Post by Riyad » Sat Oct 04, 2003 3:15 pm

hey dont try to allocate memory dynamically . it would be better of if u use int array instead , not chance of invalid memory reference rather than array index out of bound .
i guess this will help
best regards
Riyad
HOLD ME NOW ,, I AM 6 FEET FROM THE EDGE AND I AM THINKIN.. MAY BE SIX FEET IS SO FAR DOWN

Dani
New poster
Posts: 5
Joined: Sun Sep 28, 2003 5:36 pm

Re: hey .........

Post by Dani » Sun Oct 05, 2003 3:43 am

Riyad wrote:hey dont try to allocate memory dynamically . it would be better of if u use int array instead , not chance of invalid memory reference rather than array index out of bound .
i guess this will help
best regards
Riyad

Hi Riyad!!

Thanks for your replay again!!! :D
I don't know what is happening!! My algorithm is ok for your inputs suggestions(thanks!!) but, the judge give me WA AGAIN!!!! I think that could be the output format but I'm not sure.

First, I tried this format:
INPUT
18 2
35 8

OUTPUT (with one blank line between lines, correct?)
18 2: 3 5 7 11

35 8: 1 2 3 5 7 11 13 17 19 23 29 31

After, I tried this format:
18 2
18 2: 3 5 7 11

35 8
35 8: 1 2 3 5 7 11 13 17 19 23 29 31

What is the correct format?
My new code is (for the first output format):

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <malloc.h>

typedef struct{
int n;
int c;
} Entrada;

int eh_primo(int num)
{
int i;
double raiz;

raiz = (int)sqrt(num);
for (i=2;i<=raiz;i++)
{
if ((num%i) == 0)
return(0);
}
return(1);
}

void main(void)
{
int n=0, i=0, j=0, cont=0, c=0, print=0, a=0, b=0;
int A[1000], centro=0, ini=0, fim=0, qtd=0;
Entrada ent[2000];


while (scanf("%d %d",&a, &b) == 2)
{
ent[qtd].n = a;
ent[qtd].c = b;
qtd++;
}


for (j=0; j<qtd; j++)
{
n = ent[j].n;
c = ent[j].c;
cont = 0;
centro = 0;
ini = 0;
fim = 0;
print = 0;
for (i=1;i<=n;i++)
{
if (eh_primo(i))
{
A[cont] = i;
cont++;
}
}

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

if (c == 1)
{
print = cont/2;
printf(" %d",A[print]);
}

else if ((cont%2)==0)
{
centro = (cont/2);
ini = centro - c;
fim = centro + c -1;
if (ini < 0){ini = 0; fim = cont-1;}
for (print=ini; print<=fim; print++)
printf(" %d", A[print]);

}
else
{
centro = cont/2;
ini = centro - c + 1;
fim = centro + c - 1;
if (ini < 0){ini = 0; fim = cont-1;}
for (print=ini; print<=fim; print++)
printf(" %d", A[print]);
}
printf("\n\n");
}
}

Could you help me again? :lol:

User avatar
Riyad
Experienced poster
Posts: 131
Joined: Thu Aug 14, 2003 10:23 pm
Location: BUET
Contact:

yes u got it right

Post by Riyad » Sun Oct 05, 2003 6:20 am

i guess it is the output format which is causing u WA . u r printing 2 new lines instead of one .

her is my print() function , i guess which can help u in this case .

Code: Select all

void print(int length , int c){

	register int i,x,pos,check;

	if((length+1)%2==0){

		x=2*c;

	}
	else{
		x=2*c - 1;
	}
	if(x>length){

		for(i=0;i<=length;i++){

			printf("%d ",prime[i]);
		}


	}

	else{

		pos=((length+1)-x)/2;
		for(i=pos,check=0;check<x;i++,check++){
			printf("%d ",prime[i]);


		}

	}
	printf("\n");

}
Best Regards
Riyad
HOLD ME NOW ,, I AM 6 FEET FROM THE EDGE AND I AM THINKIN.. MAY BE SIX FEET IS SO FAR DOWN

User avatar
Riyad
Experienced poster
Posts: 131
Joined: Thu Aug 14, 2003 10:23 pm
Location: BUET
Contact:

Post by Riyad » Sun Oct 05, 2003 6:24 am

i guess this is what is causing u WA .
else{
..............
...............
for (print=ini; print<=fim; print++)
printf(" %d", A[print]);
}
printf("\n\n");<--------------------------this is causing u WA
Try this , better be Ac next time.
:D

Riyad
HOLD ME NOW ,, I AM 6 FEET FROM THE EDGE AND I AM THINKIN.. MAY BE SIX FEET IS SO FAR DOWN

User avatar
Riyad
Experienced poster
Posts: 131
Joined: Thu Aug 14, 2003 10:23 pm
Location: BUET
Contact:

Post by Riyad » Sun Oct 05, 2003 6:30 am

u r output format was wrong but it is not the only error . may be a error in the algo. i changed the output format and submitted but got wa . so some other prob.
HOLD ME NOW ,, I AM 6 FEET FROM THE EDGE AND I AM THINKIN.. MAY BE SIX FEET IS SO FAR DOWN

ping
New poster
Posts: 2
Joined: Thu Oct 02, 2003 3:34 pm

thanks a lot

Post by ping » Mon Oct 06, 2003 11:19 am

thanks......... :D :D :D :D :P

i got AC thanks a lot :D

seadoo
New poster
Posts: 12
Joined: Mon Dec 15, 2003 6:16 pm

Post by seadoo » Fri Jan 02, 2004 8:05 pm

But there should be an empty line between each case, so \n\n is fine, i guess.

seadoo
New poster
Posts: 12
Joined: Mon Dec 15, 2003 6:16 pm

Post by seadoo » Fri Jan 02, 2004 8:15 pm

Was the only change the additional line? I comapred my input/output with that of your program and they are the same, but I get WA. Didn't try to submit your program, though.

Bug!
New poster
Posts: 24
Joined: Thu Oct 30, 2003 10:19 am

Post by Bug! » Sun Jan 04, 2004 7:33 am

I tried to compile your program and When your program give:

input:
100 1
500 1

output:
100 1: 41

500 1: 223

I think the output should be:
output:
100 1: 37 41
500 1: 211 223

Maybe this make you'va got wa.
Regard,
Andre

User avatar
_.B._
Experienced poster
Posts: 160
Joined: Sat Feb 07, 2004 7:50 pm
Location: Venezuela
Contact:

I/O.

Post by _.B._ » Mon Apr 19, 2004 8:33 pm

Greetings!.
I've tried all Input I've found, and get what's supposed to be the right Output.
Please, post Output for this Input.
Thanks in advance.

Code: Select all

1000 85
1000 84
998 85
998 84
997 85
997 84
996 84
996 83
Hmmm... seems it'll be a bit long, but I believe maybe my error lies in those edge numbers.
If too long, please Private Message it to me.
_.

Bug!
New poster
Posts: 24
Joined: Thu Oct 30, 2003 10:19 am

Post by Bug! » Tue Jul 20, 2004 3:48 am

Here is the output....

1000 85: 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

1000 84: 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

998 85: 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

998 84: 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 85: 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

997 84: 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

996 84: 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

996 83: 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

Cheers....
Andre

User avatar
_.B._
Experienced poster
Posts: 160
Joined: Sat Feb 07, 2004 7:50 pm
Location: Venezuela
Contact:

Thanks!

Post by _.B._ » Tue Aug 17, 2004 7:42 pm

Well, thanks for the help!
I realized I was getting a different output for the 996 84 case. It made me realize I wasn't initializing my "left number" rigth.
ACed now 8)

Keep posting!
_.

Arm.Turbo
New poster
Posts: 21
Joined: Wed Aug 11, 2004 1:20 pm

Post by Arm.Turbo » Fri Sep 10, 2004 7:13 am

I pass all tested that given in that topic. Pls give the correct output for this testcases:

Code: Select all

1 1
2 1
3 1
4 1
5 1
1 2
2 2
3 2
4 2
5 2
My answers:

Code: Select all

1 1: 1

2 1: 1 2

3 1: 2

4 1: 2

5 1: 2 3

1 2: 1 2

2 2: 1 2

3 2: 1 2 3

4 2: 1 2 3

5 2: 1 2 3 5

Corpse Fiend
New poster
Posts: 5
Joined: Wed Dec 17, 2003 6:18 pm
Location: Poland

Post by Corpse Fiend » Fri Sep 10, 2004 3:10 pm

This input:

Code: Select all

1 2
should give you

Code: Select all

1 2: 1
instead of

Code: Select all

1 2: 1 2

By the way, my programm passes all the tests posted here, but still gets WA after 0.342. Any hints? Maybe I could send the code to someone to check it out?


[EDIT]
Doesn't matter, just got AC.

Raiyan Kamal
Experienced poster
Posts: 106
Joined: Thu Jan 29, 2004 12:07 pm
Location: Bangladesh
Contact:

Post by Raiyan Kamal » Mon Sep 13, 2004 8:49 am

The sample cases in this forum are quite helpful. Since you are still having WA, you can chek for your output formatting and for cases like

1 0
10 0

etc.

There will be no 0 in the input, but using 0 you can detect if there is any fault in your code

Post Reply

Return to “Volume 4 (400-499)”