Page 6 of 14

Ok, my bad

Posted: Fri Apr 01, 2005 2:39 pm
by ugrash
I found my mistake (using this forum, i'm ashamed)

when you have 15 prime factors, you have an excessive "\n" ....

WA -160(Factors and factorial)

Posted: Thu Apr 07, 2005 3:49 am
by murkho
Hi,
Can anyone help me to show the bug of my coding.
Here is the coding for consideration....

Code: Select all

//Name:factors and factorials..
//no:160.......................


#include<stdio.h>
#include<memory.h>


int main()
{
	int prime[110] = {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};
	int in,i,j,t,m;
	int count[110];
	for(i = 0;i<100;i++)
		count[i] = 0;

	while(scanf("%d",&in) != EOF)
		{
		  memset(count,0,sizeof(count));
		  if(in == 0)
			  break;
		for(i = 0;prime[i]<=in && prime[i];i++)
			{
			  
			 t = in;
			 for(j = prime[i];t>=j;)
				{
				 count[j] +=  t/prime[i];
				 t = t/prime[i];		 
			 
				}
		
			}


	printf("%3d! =",in);
	for(m = 0; m<i;m++)
		{
			printf("%3d",count[prime[m]]);
			if((m+1) %15 == 0)
			printf("\n      ");

		
		}
	
		}



return 0;
}

Posted: Thu Apr 07, 2005 5:02 pm
by chunyi81
Try with this small input:

Input:
8!
7!

You get your output for both joined together.

160 (factors and factorials) WA

Posted: Fri Apr 08, 2005 4:30 pm
by murkho
When first time I saw WA in this board i thought it's a way of sharing delight.Now i know this is an error. I have one of this error in problem 160.Can anybody help me to find out the bug? Or can anybody send me some input-output set?

Code: Select all

//Name:factors and factorials..
//no:160.......................
#include<stdio.h>
#include<memory.h>
int main()
{
	int prime[110] = {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};
	int in,i,j,t,m;
	int count[110];
	for(i = 0;i<100;i++)
		count[i] = 0;
	//freopen("c:\\160.txt","r",stdin);
	//calculating factors here.
	while(scanf("%d",&in) != EOF)
		{
		  memset(count,0,sizeof(count));
		  if(in == 0)
			  break;
		for(i = 0;prime[i]<=in && prime[i];i++)
			{			  
			 t = in;
			 for(j = prime[i];t>=j;)
				{
				 count[j] +=  t/prime[i];
				 t = t/prime[i];		  
				}		
			}
		//printing the result...
	printf("%3d! =",in);
	for(m = 0; m<i;m++)
		{
			printf("%3d",count[prime[m]]);
			if((m+1) %15 == 0)
			printf("\n      ");		
		}
	printf("\n");	
		}
return 0;
}

Posted: Fri Apr 08, 2005 5:18 pm
by mf
Your program prints unnecessary empty line when 47 <= n <= 52.

Can't find error in Problem 160

Posted: Tue Jun 14, 2005 4:56 pm
by 45793HM
Can someone help me.
Please !!
My code:
#include <stdio.h>
int main(void)
{ int i,j,k,n,soma[25],p[]={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};

scanf("%d",&n);
while(n>=2)
{ if ((n>=2) && (n<=100))
{ for (i=0;i<26;i++) soma=0;

for (i=2;i<=n;i++)
{
j=i;
k=0;
while (j>1)
if ((j%p[k])==0)
{j/=p[k];
soma[k]++;}
else
k++;
}

i=25;
while(soma[i--]==0);
i++;
printf("%3d! =",n);
for (j=0;j<=i;j++)
{
if (((j%15)==0) && (j>0)) printf("\n "); /* there are 6 spaces */
printf("%3d",soma[j]);
}
printf("\n");
}
scanf("%d",&n);
}
}

Posted: Tue Jun 14, 2005 8:41 pm
by Mohammad Mahmudur Rahman
What's acutally wrong? Did you recieved a WA or something else or just couldn't managed to match the sample I/O? I tested your code & it printed

Code: Select all

0! = 
for all the inputs. :roll:
Btw, why do you adopt this peculiar way to handle multiple cases? I wonder whether it really works or not. You may use this

Code: Select all

while(scanf(" %d",&n)==1)
{
        if(!n)
             break;
     
    //.... do some processing

}

Allway's WA error, the exact problem in Pascal works fine

Posted: Tue Jun 14, 2005 10:42 pm
by 45793HM
I've modified the program to this and it does'nt work.
i have check all the results form 2 to 100 , all are good
i try several inputs, and nothing.
i stil don't understand

#include <stdio.h>
int main(void)
{ int i,j,k,n,soma[25],p[25]={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};

while(scanf(" %d",&n)==1)
{
if (!((n>=2) && (n<=100))) break;

for (i=0;i<26;i++) soma=0;

for (i=2;i<=n;i++)
{
j=i;
k=0;
while (j>1)
if ((j%p[k])==0)
{j/=p[k];
soma[k]++;}
else
k++;
}
i=25;
while(soma[--i]==0);

printf("%3d! =",n);
for (j=0;j<=i;j++)
{
if (((j%15)==0) && (j>0)) printf("\n ");
printf("%3d",soma[j]);
}
printf("\n");
}
}

Re: Allway's WA error, the exact problem in Pascal works fin

Posted: Wed Jun 15, 2005 12:27 am
by Mohammad Mahmudur Rahman
Well, you've eventually compelled me to do some debugging, :wink: Anyway,
You've used the following code block for initialization -

Code: Select all

for (i=0;i<26;i++) soma[i]=0;
That means your program accesses #0 to #25 index of that array i.e. it requires at least 26 cells. But you've declared -

Code: Select all

soma[25]
So, array goes out of bound & overwrites something else. While debugging your program I found that every time the initialization loop ends, n turns to 0. Then the rest of the program could happily consider it's job done by printing

Code: Select all

0! = 
for any input. You are lucky (or unlucky, whichever you think :wink:) that the variable n was not overwritten while running in your pc. But you never know, how it will behave while running in judge. There is every chance that it'll go the wrong way. So, be carefull to allocate sufficient memory.

Finally, when your output goes to second line, is it correctly formatted? I'll bet for the negative.
:P
/* Hint: use printf("%9d"....) in the second line */

Thanks - it works

Posted: Wed Jun 15, 2005 12:36 am
by 45793HM
Thanks a lot.

now i can sleep better.

Posted: Wed Jun 15, 2005 12:43 am
by Mohammad Mahmudur Rahman
Nice to know that it finally works :) . It's behaviour surprised me, too.

The judge must gone mad with 160

Posted: Fri Sep 16, 2005 7:13 am
by Tanu

Code: Select all

#include<stdio.h>
#include<math.h>
#define N 101
main()
{
	int 
i,j,c,record[N+5][30],max[27],count,input,primes[]={2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,61,67,71,73,79,83,89,93,97};
	
	for(i=0;i<N;i++)
		for(j=0;j<25;j++)
			record[i][j]=0;

	for(i=0;i<25;i++)
		max[i]=0;

	for(j=1;j<=N;j++)
	{
		c=j;
		for(i=0;i<25;i++)
		{
			record[j-1][i]=max[i];
			while((c%primes[i])==0)
			{				
				record[j-1][i]++;
				c/=primes[i];
			}	
			max[i]=record[j-1][i];			
		}
	}
	while(1)
	{
		scanf("%ld",&input);
		if(input==0)
			break;
		printf("%3ld! =",input);
		count=0;
		for(i=0;i<25;i++)
		{
			if(record[input-1][i]==0)
			{
				
			}
			else
			{
				count++;
				printf("%3ld",record[input-1][i]);
			}
			if(count>14)
			{
				count=0;
				printf("\n      ");
			}
		}
		printf("\n");
	}
}
I show nothing Wrong(It may be my less eye power)...
Bue tried it 6 times...
Plz go through once my code...

Posted: Sat Sep 17, 2005 5:34 am
by chunyi81
The judge is not wrong in judging your code WA.

After reading your code I found one problem. Are you sure you have all the prime numbers between 1 and 100 in your primes array? I see one missing.

Thanx

Posted: Sat Sep 17, 2005 7:36 am
by Tanu
Thanx a lot...
It was my fool...
Now I got acc...
Good luck...
Thanks again...
Bye :P

160 - WA

Posted: Fri Nov 25, 2005 2:29 am
by smilitude
hmm... only i know in this whole world... what a great collection of WA i got! let me share one of those...

Code: Select all

/*
160 factors and factorials
submission 1 WA
coded at 5:51am oct 14,05

i once got an infinite loop here coz, i divided the loop constant(i) instead of number!
ha ha ha!

i corrected, then submitted to get a wa...
*/
CUTTTTTTTTTTTTTTTTTTTTTT!!!