Page 11 of 14

160 PE; Please help

Posted: Sun Mar 18, 2007 3:32 am
by rana_cse_ruet
here is the output

[
1
1!=
53
53!= 49 23 12 8 4 4 3 2 2 1 1 1 1 1 1
1
2
2!= 1
100
100!= 97 48 24 16 9 7 5 5 4 3 3 2 2 2 2
1 1 1 1 1 1 1 1 1 1
]

should the above output show presentation error?
please help......
[/code]

Posted: Mon Mar 19, 2007 4:34 am
by abdullah<cse du>
Rana,

I think you don't read the output section clearly.
Output will consist of a series of blocks of lines, one block for each line of the input. Each block will start with the number N, right justified in a field of width 3, and the chracters `!', space, and `='. This will be followed by a list of the number of times each prime number occurs in N!.
Your posted o/p does not match with the problem's o/p section.

Thanks.
ABDULLAH

can any one known me,why 160 problem is CE

Posted: Tue Mar 27, 2007 5:26 am
by mohidul18
#include<stdio.h>
int pr[26]={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};
void factor(int c,int a[])
{ if(c==1)return ;
factor(c-1,a);
int i;
for( i=0;pr<=c;i++){
while(!(c%pr)){a++;c=c/pr;}}
}

void main()
{
int n,i ;
while(scanf("%d ",&n)&&n)
{printf("%3d! = ",n);
int p[26]={0};
factor(n,p);
i=0;
printf("%3d",p[i++]);
while(p){
if(i%15)printf("%3d",p[i++]);
else printf("\n%10d",p[i++]);
} printf("\n");

}}

Posted: Mon Apr 16, 2007 10:20 pm
by Jan
Search your problem first. Don't open a new thread if there is one already.

Posted: Thu Apr 19, 2007 7:32 pm
by henry1007
I also got a PE...I just can't figure out y.
I've tried inputting all the way from 2 to 100 and check the output - unless I missed sth, there should be no problem.
Here's my code, it would be great if someone can help me out :(

Code: Select all

Code Deleted
P.S. I will delete the code once it's got modified and accepted.

Posted: Fri Apr 20, 2007 6:30 am
by abdullah<cse du>
henry1007,

Your output section is not correct. Another wrong is that- you take all the input and after getting the zero input you give output. It is not necessary. Take a input and give output. I give some input for test.

Code: Select all

80
70
30
50
100
0

Code: Select all

 80! = 78 36 19 12  7  6  4  4  3  2  2  2  1  1  1
        1  1  1  1  1  1  1
 70! = 67 32 16 11  6  5  4  3  3  2  2  1  1  1  1
        1  1  1  1
 30! = 26 14  7  4  2  2  1  1  1  1
 50! = 47 22 12  8  4  3  2  2  2  1  1  1  1  1  1
100! = 97 48 24 16  9  7  5  5  4  3  3  2  2  2  2
        1  1  1  1  1  1  1  1  1  1

Posted: Fri Apr 20, 2007 3:37 pm
by henry1007
abdullah<cse du> wrote:henry1007,

Your output section is not correct. Another wrong is that- you take all the input and after getting the zero input you give output. It is not necessary. Take a input and give output. I give some input for test.

Code: Select all

80
70
30
50
100
0

Code: Select all

 80! = 78 36 19 12  7  6  4  4  3  2  2  2  1  1  1
        1  1  1  1  1  1  1
 70! = 67 32 16 11  6  5  4  3  3  2  2  1  1  1  1
        1  1  1  1
 30! = 26 14  7  4  2  2  1  1  1  1
 50! = 47 22 12  8  4  3  2  2  2  1  1  1  1  1  1
100! = 97 48 24 16  9  7  5  5  4  3  3  2  2  2  2
        1  1  1  1  1  1  1  1  1  1
Thx for considering my problem. However, I still can't find out wt's wrong with my output section - and for the test case you've given, my program gives exactly the same output.

Edit: I finally resort to rewriting in C (replacing those cout with printf, etc) and got accepted. Still hv no idea y original C++ code has PE. Maybe problem with setw in iomanip, I suppose.

acm-160

Posted: Fri May 25, 2007 8:31 pm
by hridoy
can anyone please tell why I m getting PE in acm-160. I read the previos topics but still I m getting PE

#include<stdio.h>
long prime (long n)
{
long i,z=0;
for(i=2;i<=n/2;i++)
if(n%i==0)
z=1;
if(z==0)
return 1;
else
return -1;
}
main()
{
long x[100],i,j,n,k,z,m;
while(1)
{
scanf("%ld",&n);
if(n==0)
break;
for(i=0;i<100;i++)
x=0;
z=1;
m=n;
for(;n>1&&n<=100;n--)
{
z*=n;
j=0;
for(i=2;i<=n;i++)
{
k=prime(i);
if(k==1)
{
while(z%i==0)
{
z/=i;
x[j]++;
}
j++;
}
}
}
printf("%3ld! =",m);
i=0;
do
{
if(i==15)
printf("%9ld",x);
else
printf("%3ld",x);
i++;
if(i==15)
printf("\n");
}while(x!=0);
printf("\n");
}
}

Posted: Sat May 26, 2007 3:05 pm
by Jan

Posted: Wed Jul 18, 2007 2:59 pm
by newton
thanx a lot.


it is accepted.

Posted: Wed Jul 18, 2007 3:31 pm
by Jan
Why are you calculating prime upto 100000? Check your code with 48, 49. Your code prints an extra line with some spaces.

Hope it helps.

I get PE 160 plz help

Posted: Sun Dec 23, 2007 8:15 am
by Sayeef

Code: Select all

#include<stdio.h>
#include<math.h>
int prime[10000]={0};
void gen()
	{
		  long i=0,j=0,chk=1,index=3;
		  prime[0]=1;
		  prime[1]=2;
		  prime[2]=3;
		for(j=5;j<=10000;j++)
			{
			for(i=1;prime[i]<=sqrt(j);i++)
				{
					chk=j%prime[i];
					if(chk==0)
					break;

				}
				   if(chk)
						prime[index++]=j;
			}
  }

int main()
{
	int i,k,p,j;
	int fact,sum=0,count=0;
	gen();
	while(scanf("%d",&fact)&&fact!=0)
	{
		
		count=0;
		printf("%3d ! = ",fact);
		for(i=1;prime[i]<=fact;i++)
		{
			sum=0;
			for(j=1;j<10000;j++)	
			{	
				p=pow(prime[i],j);
				if(p>fact)break;
				else
				{
					sum+=floor(fact/p);
				}
			}
			if(count>=15)
			{
				printf("\n");
				printf("        ");	
				count=0;
			}
			printf("%3d ",sum);
			count++;
		}
		printf("\n");
	}
	
return 0;
}

Posted: Sun Dec 23, 2007 1:06 pm
by Samiul
Your output format is not ok.

Input:
5
53
0

Your output: ("0" denotes space)

0050!0=0003000100010
0530!0=0049002300120008000400040003000200020001000100010001000100010
000000000010

Correct output:

005!0=003001001
053!0=049023012008004004003002002001001001001001001
000000001

Desperate WA

Posted: Sun Dec 30, 2007 11:48 pm
by Brainless
Hi,

I heve followed your suggestions, but I still get WA.

My code :

Code: Select all

#include <iostream>
#include <vector>
#include <map>
#include <iomanip>
#include <list>
using namespace std;

void get_prime_factors(const int& n, vector<int>& v)
{
	int k(n);
	for(int i=2; k!=1; ++i)
	{
		while(k%i == 0)
		{
			v.push_back(i);
			k/=i;
		}
	}
}

map<int, map<int, int> > _dec;

void set_dec()
{
	_dec[1][2] = 0;
	_dec[2][2] = 1;
	vector<int> v;
	for(int n=3; n<=100; ++n)
	{
		get_prime_factors(n, v);
		const int SIZE(v.size());
		_dec[n] = _dec[n-1];
		for(int j=0; j<SIZE; ++j)
		{
			_dec[n][v[j]]++;
		}
		v.clear();
	}
}

int main()
{
	set_dec();
	int n;
	cin >> n;
	vector<int> v;
	while(n!=0)
	{
		v.push_back(n);
		cin >> n;
	}

	const int SIZE(v.size());
	
	for(n=0; n<SIZE; ++n)
	{
		cout.setf(ios::right);
		cout << setw(3) << v[n] << "! =";
		int count(0);
		int space(3);
		for(map<int, int>::iterator i(_dec[v[n]].begin());
			i!= _dec[v[n]].end(); ++i)
		{
			cout << setw(space) << i->second << flush;
			count++;
			if(count % 15 == 0)
			{
				cout << endl;
				space = 9;
			}
			else
			{
				space = 3;
			}
		}
		cout << endl;
		cout.unsetf(ios::right);
	}
	return 0;
}
I need help, please !

Posted: Mon Dec 31, 2007 12:13 am
by Brainless
Ok, finally I found :

The output was incorrect with 50! : my program output a new line, which should not be .

:wink: