160 - Factors and Factorials
Moderator: Board moderators
-
- New poster
- Posts: 7
- Joined: Mon Mar 05, 2007 9:59 am
160 PE; Please help
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]
[
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]
-
- New poster
- Posts: 39
- Joined: Mon Dec 04, 2006 2:18 pm
- Location: Bangladesh(CSE DU)
- Contact:
Rana,
I think you don't read the output section clearly.
Thanks.
ABDULLAH
I think you don't read the output section clearly.
Your posted o/p does not match with the problem's o/p section.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!.
Thanks.
ABDULLAH
can any one known me,why 160 problem is CE
#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");
}}
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");
}}
i dun like them who likes me
Search your problem first. Don't open a new thread if there is one already.
Ami ekhono shopno dekhi...
HomePage
HomePage
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
P.S. I will delete the code once it's got modified and accepted.
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
Last edited by henry1007 on Sun Apr 22, 2007 10:46 pm, edited 1 time in total.
-
- New poster
- Posts: 39
- Joined: Mon Dec 04, 2006 2:18 pm
- Location: Bangladesh(CSE DU)
- Contact:
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.
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.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
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
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");
}
}
#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");
}
}
Read the thread http://online-judge.uva.es/board/viewtopic.php?t=17684 before posting.
Ami ekhono shopno dekhi...
HomePage
HomePage
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.
Hope it helps.
Ami ekhono shopno dekhi...
HomePage
HomePage
I get PE 160 plz help
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;
}
Desperate WA
Hi,
I heve followed your suggestions, but I still get WA.
My code :
I need help, please !
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;
}