Page 8 of 14

160: giving WA

Posted: Tue Feb 28, 2006 8:36 pm
by opportunity
i am getting WA but unable to sort out where error occurred. plz someone help me out.

Code: Select all

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

int primes[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}; 

int main()
{
	int index = -1;
	int N,numOfPrime,multipleOfPrime;
	int i,k,j;
	while(scanf("%d",&N)==1)
	{
		if(N==0)
			break;
		for(i=0;i<25;i++)
		{
			index = -1;
			if(primes[i]>=N)
			{
				index = i;
				break;
			}
		}

		printf("%3d! =",N);

		for(j=0;j<=index;j++)
		{
			numOfPrime = 0;
			multipleOfPrime = 1;

			for(k=0;multipleOfPrime<=N;k++)
			{
				multipleOfPrime*=primes[j];
				numOfPrime+=(int)floor(N/multipleOfPrime);
			}
			if(numOfPrime)
			{
				if(j&&(j%15)==0)
				{
					printf("\n%9d",numOfPrime);
					continue;
				}
				/*else*/ 
					printf("%3d",numOfPrime);
			}
		}
		printf("\n");
	}

	return 0;
}

Posted: Tue Feb 28, 2006 10:25 pm
by little joey
Look what happens when the input value is bigger than 97.

thanks guru

Posted: Wed Mar 01, 2006 9:23 pm
by opportunity
thank u so much. i was missing a checking condition. now it is accepted

o_o

Posted: Fri Mar 03, 2006 8:24 am
by sds1100
oo

Posted: Fri Mar 03, 2006 8:43 am
by sds1100
sorry i don't know your program..
sorry.sorry.sorry.sorry.sorry.

160 Help Me!! << C

Posted: Mon Mar 13, 2006 10:31 am
by LemonMint
#include <stdio.h>
int Pri[100];

void PrimeC(int a)
{
int i;

for(i=2;;i++){
if( a % i == 0 ){
while(a % i == 0){
a=a/i;
Pri++;
}
}
if( a == 1 ) break;
}
}

void Clear(){
int i;
for(i=1;i<=100;i++)
Pri=0;
}

void main()
{
int i,j,n,tmp,cnt=0,num=0;

while(scanf("%d",&n))
{
if( n == 0 ) break;
for(i=2;i<=n;i++) PrimeC(i);

printf("%3d! =",n);

for(i=2;i<=n;i++){
tmp=i;
for(j=1;j<=i-1;j++){
if( tmp % j == 0 ) cnt++;
if( cnt > 1 ) break;
}
if( cnt > 1 ) cnt=0;
else{
printf("%3d",Pri);
num++;
if( num % 15 == 0 ) printf("\n ");
cnt=0;
}
}
Clear();
if( num % 15 != 0 ) printf("\n");
else printf("\b\b\b\b\b\b");
num=0;
}
}

I don't know what's wrong.
Plz help me !!! :oops:

Posted: Mon Mar 13, 2006 10:51 am
by Darko
Maybe it's:

int Pri[100];

and

Pri[100] = 0; ?

Darko

160 - Help!

Posted: Fri Mar 24, 2006 9:09 pm
by f.eliel
I have 3 problems with my code:

When i test with the sample input 53, it doesn't work (it seems that unsigned long int isn't big enough, but i don't know how to fix it).

When i test whit 7 or more numbers it doesn't work and i don't know why.

And i don't know how to jump to the next line when the output passes 15 numbers.

Here is my code:

Code: Select all

#include <stdio.h>

int count[25];
int y;
void prime(unsigned long a);

int main()
{
   int i = 0, w, x, j, n[i];
   unsigned long fat[i];
       
   while (scanf("%d", &n[i]) == 1) {
      if (n[i] == 0) break;
      i++;
   }
   w = 0;
   while (w < i) {
      fat[w] = n[w];
      j = (fat[w]-1);
      while (j > 1) {
         fat[w] *= j;
         printf("%lu ", fat[w]);
         j--;
      }
      prime(fat[w]);
      printf("%3d! =", n[w]);
      for (x = 0; x <= y; x++)
         printf("%3d", count[x]);
      printf("\n");
      w++;
   }
   return 0;
}         

void prime(unsigned long a)
{
   int x;
   int primes[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, 93};
   
   for (x = 0; x < 25; x++)
      count[x] = 0;
   for (x = 0;; x++) {
      while (!(a % primes[x])) {
         a /= primes[x];
         count[x]++;
      }
      if (a == 1) {
         y = x;
         break;
      }
   }
}
Thanks for any help you can give.

Posted: Sat Mar 25, 2006 8:48 am
by chunyi81
I see a lot of problems in your program.

1) You have a prime number < 100 that is missing in your primes array.
2) Why are you declaring an array n of size 0 since i is initialized to 0 and you declare int n on the same line of code? You are going to get runtime error this way. Why don't you process input as you read it instead of using an array to hold the input?
3) There is no need to compute the factorial even though the input can be as large as 100.
4) To go to the next line after 15 numbers, you can use a counter to keep track of how many numbers you have printed.

Read past threads on this problem to get some hints on solving this problem.

160 WA

Posted: Tue May 30, 2006 10:42 am
by ayeshapakhi
dear fellows......
pls help abt 160...it would be better if u can provide me some test cases...
or if there's any mistake abt the formatting pls help me fixing....

Code: Select all

#include <stdio.h>
#define size 25

void main()
{
	//freopen("in.txt","r",stdin);
	//freopen("Mout.txt","w",stdout);

	long int prime[size]={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};
	long int counter[size],number,i,j,temp;

    while (scanf("%ld",&number)==1 && number)
	{
		for(i=0; i<size; i++) counter[i]=0;

		for(j=number; j>1; j--)
			for(i=0; i<size; i++)
			{ 
				temp=j;
				while(temp%prime[i]==0)
				{
					counter[i]++;
					temp=temp/prime[i];
				}
			}

			printf("%3ld! =",number);
			for(i=0; i<size; i++)
			{
				if (prime[i]>number) break;
				printf("%3ld",counter[i]);

				if( i==14)printf("\n      ");
			}
			printf("\n");
	}
}

thanks a lot..........

Posted: Tue May 30, 2006 2:10 pm
by dumb dan
Try this input and see if you can spot your error (and don't forget to remove your code after you get AC).

input:

Code: Select all

45
47
49
0

Posted: Tue May 30, 2006 10:23 pm
by sohel_acm
Hi
You should change your code as follow

Code: Select all

for(i=0; i<size; i++) 
         { 
             if(i==15) printf("\n      ");
            if (prime[i]>number) break; 
            printf("%3ld",counter[i]); 

             
         }
 
Unless your program will creat an extra line in special cases.
Good Luck.

Posted: Sat Jun 03, 2006 4:17 pm
by kwedeer
I get presentation error for my solution (yet - it appears on accpeted list of my profile - but anyway - I would feel better if I got accepted without presentation error) - so - help me please:

here is my code:
code delete upon request.

and here the output for all the possible test cases (so - what's wrong?):
all the possible answers deleted upon request

btw - here is Mathematica routine for answer check:
FactorInteger[100!]

Posted: Sat Jun 03, 2006 4:19 pm
by kwedeer
well - I see that - at least - this board software delete the blank spaces in if they are the first symbols in line... Maybe - judge does the same and this is the cause of PE? Is so - can You suggest how to code these blank spaces in Pascal to be perceived normally?

Thanx in advace!

small addition - my result file can be read by notepad or wordpad as one that is presented as required by task... So - I hope that Judge is at least as smart as MS :)))

Posted: Sat Jun 03, 2006 4:44 pm
by little joey
Your last line of output should also end in a return, so add an extra writeln at the end of your code.
To prevent the board from skipping leading spaces, place your output text between code tags, just as you did with your program.

Your code and your output are spoilers for this problem. Please delete them.