Page 1 of 14

### problem 160

Posted: Sun May 12, 2002 7:42 am
Can you tell me ,what will be output ,if I input 100 and 97? Please tell me soon.

Posted: Sun May 12, 2002 1:51 pm

Code: Select all

``````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
97! = 94 46 22 14  8  7  5  5  4  3  3  2  2  2  2
1  1  1  1  1  1  1  1  1  1
``````
Before 97 there should be a space, but it is not displayed.

### problem 160

Posted: Tue May 21, 2002 7:33 am
Can you tell me what will be the output, if I input 2 and 1 and do I need to use "FILE" for this program? Please tell me soon.I think my program is right , but the judge's reply is "wrong answer, it ran during 0:10 seconds".What can I do now? [/code][/b][/c]

### HI~

Posted: Tue May 21, 2002 9:33 am
2! = 1

and I think no need to test for the input of 1, since the smallest input is 2.

And what do u meant my FILE? The IO of the problem is the same as the others.

### problem 160

Posted: Wed May 22, 2002 8:11 am
Can you tell me why I always get "wrong answer"?How can I send you my code ?Please tell me soon.

Posted: Wed May 22, 2002 4:09 pm
You can send the code to my email at your convenience

### Help

Posted: Wed May 22, 2002 7:34 pm
If you still fail on this problem try visit link below or mail me your code.

http://www.comp.nus.edu.sg/~stevenha/pr ... /vol1.html

-novice ### problem 160 code

Posted: Thu May 23, 2002 8:45 am
This is my problem 160 code:
[url]
[c][code][quote]
int main()
{
int x,p,f;
int i,y,count=0,n,k=0,l=0,z,j=0;
for(i=2;i<=100;++i)
{
for(y=1;y<=i;++y)
if(i%y==0)
++count;
if(count==2)
{
x[j]=i;
count=0;
++j;

}
else
count=0;
}
while(scanf("%d",&n)==1 && n!=0)
{
if(n>=2 &&n<=100)
{
printf("%3d! =",n);
j=0,count=0;
for(i=2;i<=n;++i)
{
p[j]=i;
++j;
}
for(i=0;i<=25;++i)
{

for(z=0;z<n-1;++z)
if(p[z]!=0)
++count;
if(count>=1)
{
count=0;
for(z=0;z<n-1;++z)
{
if(p[z]!=0 && p[z]%x[i]==0)
{
while(p[z]%x[i]==0) {
p[z]=p[z]/x[i];
++count;
}
if(p[z]==1)
p[z]=0;
}
}
if(k<15)
{
printf("%3d",count);
count=0;
++k;
}
else if(k>=15)
{
f[l]=count;
count=0;
++l;
++k;
}
}
else
{
if(k>=16)
{
printf("\n%9d",f);
for(z=1;z<l;++z)
printf("%3d",f[z]);
for(z=0;z<l;++z)
f[z]=0;
l=0;
break;
}
else
break;
}
}
k=0;
}
}
return 0;
}
[/quote][/code][/c][/url]

### Re: Help

Posted: Sun May 26, 2002 6:49 am
Please help me to solve Problem 160.This is my program code:
#include<stdio.h>
int main()
{
int x,p,f;
int i,y,count=0,n,k=0,l=0,z,j=0;
for(i=2;i<=100;++i)
{
for(y=1;y<=i;++y)
if(i%y==0)
++count;
if(count==2)
{
x[j]=i;
count=0;
++j;

}
else
count=0;
}
while(scanf("%d",&n)==1 && n!=0)
{
if(n>=2 &&n<=100)
{
printf("%3d! =",n);
j=0,count=0;
for(i=2;i<=n;++i)
{
p[j]=i;
++j;
}
for(i=0;i<=25;++i)
{

for(z=0;z<n-1;++z)
if(p[z]!=0) ++count;
if(count>=1)
{
count=0;
for(z=0;z<n-1;++z)
{
if(p[z]!=0 && p[z]%x==0)
{
while(p[z]%x==0)
{
p[z]=p[z]/x;
++count;
}
if(p[z]==1)
p[z]=0;
}
}
if(k<15)
{
printf("%3d",count);
count=0;
++k;
}
else if(k>=15)
{
f[l]=count;
count=0;
++l;
++k;
}
}
else
{
if(k>=16)
{
printf("\n%9d",f);
for(z=1;z<l;++z)
printf("%3d",f[z]);
for(z=0;z<l;++z)
f[z]=0;
l=0;
break;
}
else
break;
}
}
k=0;
}
}
return 0;
}

Posted: Sun May 26, 2002 4:35 pm
You can compare me code
My code can do the right way

Code: Select all

``````[c]
#include<stdio.h>

int main(void)
{
int input=0;

while(1==scanf("%d", &input))
{
if(0==input)
return 0;
else
{
int array=
{{2,0},{3,0},{5,0},{7,0},{11,0}
,{13,0},{17,0},{19,0},{23,0},{29,0}
,{31,0},{37,0},{41,0},{43,0},{47,0}
,{53,0},{59,0},{61,0},{67,0},{71,0}
,{73,0},{79,0},{83,0},{89,0},{97,0}};

int i=0, j=0, temp=0;

for(i=0; i<input; i++)
{
for(temp=input-i, j=0; 1!=temp, j<25; j++)
{
if(0==temp%array[j])
{
array[j]++;
temp/=array[j];
j--;
}
}
}

printf("%3d! =", input);
for(i=0; array[i]<=input&&i<25; i++)
{
if(0==(i+1)%16)
printf("\n      ");
printf(" %2d", array[i]);
}
printf("\n");
}
}

return 0;
}[/c]``````

### thank you

Posted: Mon May 27, 2002 7:40 am
Thank you for helping me to slove the problem 160.

### 160

Posted: Thu Jul 11, 2002 12:39 pm
Why does this code alway get WA? I check the code many times and can't find out the bug.
[c]
#include<stdio.h>
#define YES 1
#define NO 0
void main(void)
{
int prime,i,is_prime,x,may_be_prime=5,gap=4,n,ans,temp,count;
prime=2,prime=3,prime=5;
for(x=3;x<25;)
{
is_prime=YES;
gap=6-gap;
may_be_prime+=gap;
for(i=0;prime*prime<=may_be_prime && is_prime;i++)
if(may_be_prime%prime==0)
is_prime=NO;
if(is_prime)
prime[x++]=may_be_prime;
}
while(1)
{
scanf("%d",&n);
if(n==0)
break;
for(x=0;x<25;x++)
ans[x]=0;
for(x=1;x<=n;x++)
{
temp=x;
for(i=0;i<25;i++)
if(temp%prime==0)
while(temp%prime==0)
{
temp/=prime;
ans++;
}
}
printf("%3d! =",n);
for(x=0,count=1;x<25;x++,count++)
{
if(ans[x]!=0)
printf("%3d",ans[x]);
if(count%15==0)
printf("\n ");
}
printf("\n");
}
}
[/c]

Posted: Fri Jul 19, 2002 7:17 pm
The problem is right here:
you increased count every time.
But you should have increased count whenever you print a digit.

for(x=0,count=1;x<25;x++,count++)
{
if(ans[x]!=0)
printf("%3d",ans[x]);
if(count%15==0)
printf("\n ");
}

Posted: Sun Jul 21, 2002 4:56 am
I've got accepted. Thanx

### hey hey hey, now help me please

Posted: Mon Jul 22, 2002 12:59 pm
The following code got a WA. Why?

[cpp]#include <stdio.h>

int main() {
const int primes = {
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 fact, factors, i, j;

while (true) {
for (i = 0; i < 25; i++)
factors = 0;

scanf("%d", &fact);
if (fact == 0)
break;

for (i = 0; i < 25; i++) {
if (primes > fact)
break;
for (j = primes; ; j *= primes) {
if (j > fact)
break;
factors += fact / j;
}
}

printf("%3d! = ", fact);
for (i = 0; i < 25; i++) {
if (i == 15)
printf("\n ");
if (factors == 0)
break;
printf("%3d", factors);
}
printf("\n");
}

return 0;
}[/cpp][/cpp]