160 - Factors and Factorials
Moderator: Board moderators
-
- New poster
- Posts: 2
- Joined: Tue Feb 12, 2008 8:52 pm
I'm continuously getting WA. Anybody PLZ HELP..
#include<stdio.h>
#include<math.h>
int main(void)
{
int frequency[25],i,N,tempN;
int prime[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};
scanf("%d",&N);
while((N>=1)&&(N<=100))
{
printf("\n%3d! =",N);
if(N==1)
{
printf("%3d",0);
goto label;
}
for(i=0;i<25;i++)
{
if(prime[i]>N)
break;
frequency[i]=0;
tempN=N;
while(tempN>=prime[i])
{
frequency[i]+=(tempN/prime[i]);
tempN/=prime[i];
}
printf("%3d",frequency[i]);
if(i==14)
printf("\n ");
}
label:
scanf("%d",&N);
}
return 0;
}
#include<stdio.h>
#include<math.h>
int main(void)
{
int frequency[25],i,N,tempN;
int prime[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};
scanf("%d",&N);
while((N>=1)&&(N<=100))
{
printf("\n%3d! =",N);
if(N==1)
{
printf("%3d",0);
goto label;
}
for(i=0;i<25;i++)
{
if(prime[i]>N)
break;
frequency[i]=0;
tempN=N;
while(tempN>=prime[i])
{
frequency[i]+=(tempN/prime[i]);
tempN/=prime[i];
}
printf("%3d",frequency[i]);
if(i==14)
printf("\n ");
}
label:
scanf("%d",&N);
}
return 0;
}
-
- New poster
- Posts: 4
- Joined: Sat Mar 01, 2008 6:04 am
160 WA
DELETE After AC
I think all output is right....
But WA....
Why???
Help me...
I think all output is right....
But WA....
Why???
Help me...
Last edited by epilos@CodeHolic on Sat Mar 01, 2008 8:54 am, edited 1 time in total.
-
- New poster
- Posts: 10
- Joined: Mon Feb 25, 2008 8:22 pm
- Location: Dhaka, Bangladesh.
sample input
HOPE THIS HELPS
Sample output53
0
Ur output53! = 49 23 12 8 4 4 3 2 2 1 1 1 1 1 1
******1
use 6 space instead of 1 in d second line and increase array size to 102 for safety & print "\n" just after printing output.53! = 49 23 12 8 4 4 3 2 2 1 1 1 1 1 1
**1
HOPE THIS HELPS

--- B HAPPY & KEEP SMILING ------
-
- New poster
- Posts: 4
- Joined: Sat Mar 01, 2008 6:04 am
Thanks.....CSEDU_1323 wrote:sample inputSample output53
0Ur output53! = 49 23 12 8 4 4 3 2 2 1 1 1 1 1 1
******1use 6 space instead of 1 in d second line and increase array size to 102 for safety & print "\n" just after printing output.53! = 49 23 12 8 4 4 3 2 2 1 1 1 1 1 1
**1
HOPE THIS HELPS
but i can't understand...
increase array size ===>> accepted....
program can't use arr[100]...
Why???
Sorry my poor English...
-
- New poster
- Posts: 20
- Joined: Thu Jan 17, 2008 10:47 pm
- Location: India
WA please help
please suggest a test case for which this code gives WA or please tell any other mistake..

Code: Select all
#include<iostream>
#include<iomanip>
using namespace std;
int main()
{
int n;
int pr[]={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 f[25],j,k;
cin>>n;
while(n!=0)
{
if(n==1)
cout<<" 1! = 0"<<endl;
else
{
for(int i=0;i<25;i++)
f[i]=0;
for(int i=n;i>=1;i--)
{
k=i;
j=0;
while(k>1)
{
if(k%pr[j]==0)
{
f[j]++;
k=k/pr[j];
}
else
j++;
}
}
int t=0;
for(int k=24;k>=0;k--)
{
if(f[k]>0)
break;
else
f[k]=-1;
}
cout.setf(ios::right);
cout<<setw(3)<<n<<"! =";
while(f[t]!=-1 && t<25)
{
cout<<setw(3)<<f[t];
t++;
if(t%15==0)
cout<<endl<<" ";
}
cout<<endl;
}
cin>>n;
}
}
"if u r goin thru hell, keep goin"
Help..
This is very annoying that i m getting wa over & over again...plzz tell me anyone where is my problem?
#include <stdio.h>
void free(int *index)
{
int i;
for(i=0;i<25;i++)
{
index=0;
}
}
void check(int num)
{
if(num>99)
printf("%d",num);
else if(num>9)
printf(" %d",num);
else
printf(" %d",num);
}
int main()
{
int num,i,j,index[30],temp;
int primee[] = {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(1)
{
scanf("%d",&num);
free(index);
if(num==0)
{
break;
}
if(num==1)
{
check(num);
printf("! = 1\n");
continue;
}
for(i=2;i<=num;i++)
{
temp=i;
for(j=0;j<25 && temp;)
{
if(temp%primee[j]==0)
{
temp/=primee[j];
index[j]++;
continue;
}
j++;
}
}
check(num);
printf("! =");
for(i=0;i<25&&index;i++)
{
check(index);
if(i==14)
printf("\n ");
}
printf("\n");
}
return 0;
}

Code: Select all
void free(int *index)
{
int i;
for(i=0;i<25;i++)
{
index=0;
}
}
void check(int num)
{
if(num>99)
printf("%d",num);
else if(num>9)
printf(" %d",num);
else
printf(" %d",num);
}
int main()
{
int num,i,j,index[30],temp;
int primee[] = {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(1)
{
scanf("%d",&num);
free(index);
if(num==0)
{
break;
}
if(num==1)
{
check(num);
printf("! = 1\n");
continue;
}
for(i=2;i<=num;i++)
{
temp=i;
for(j=0;j<25 && temp;)
{
if(temp%primee[j]==0)
{
temp/=primee[j];
index[j]++;
continue;
}
j++;
}
}
check(num);
printf("! =");
for(i=0;i<25&&index;i++)
{
check(index);
if(i==14)
printf("\n ");
}
printf("\n");
}
return 0;
}
Re: 160 WA?? format
Hi, i cant understand the output format. Anybody will help me make the format right? Following is my code.
please help
Code: Select all
#include<stdio.h>
int main(){
int numeretor,count=0,i,denomeretor,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},fact[102]={0},j=0;
int n,k,m;
for(;;){
scanf("%d",&n);
if(n==0)
break;
numeretor=n;
for(i=0;i<25;i++){
if(p[i]>n)
{k=i; break;}
denomeretor=p[i];
count=0;
numeretor=n;
for(;;){
numeretor=numeretor/denomeretor;
count=count+numeretor;
if(numeretor<=1)
{break;}
}
fact[p[i]]=count;
}
printf("%d! =",n);
for(i=0;i<k;i++){
printf("%d ",fact[p[i]]);
if((i%15)==0)
printf("\n ");
}
printf("\n");
}
return 0;
}
Re: Can't find error in Problem 160
plzzzzz help to find my error!!!!!
Thanks mf for your kind consideration 
Code: Select all
AC

Last edited by ahmed on Thu Apr 02, 2009 6:33 pm, edited 1 time in total.
Re: Can't find error in Problem 160
I am srry.I didn't understand.I just posted in all the thread that I found.I promise it won't happen again and I have deleted all of my posts.
Re: Can't find error in Problem 160
Ok, good :)
I think the error is on line 15:
This \n in it is causing your program to print an unnecessary blank line at the very beginning of the output. Your program shouldn't do that.
For the input N=47, it also prints an unnecessary a blank line in the output, fix that too.
I think the error is on line 15:
Code: Select all
printf("\n%3d! =",num);
For the input N=47, it also prints an unnecessary a blank line in the output, fix that too.
-
- New poster
- Posts: 1
- Joined: Sun Jul 19, 2009 4:56 pm
Re: Can't find error in Problem 160
Hello~ I get presentation error and don't know how to correct it..............Can anyone give me some advice on how to fix it?
Thx very much!!!
Thx very much!!!
Code: Select all
#include <stdio.h>
int main()
{
int f,i,j,n,x;
int prime[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 count[25];
while(scanf("%d",&f)==1)
{
if (f==0) break;
for (i=0; i<25; i++) count[i]=0;
for (i=2; i<=f; i++)
{
n=i;
for (j=0; j<25; j++)
{
while(n%prime[j]==0)
{
n=n/prime[j];
count[j]++;
}
}
}
printf("%3d! = ",f);
i=24;
while(count[i]==0)
{
x=i;
i--;
}
for (j=0;j<=i;j++)
{
if(j==15)
{
printf("\n ");
}
printf("%3d",count[j]);
}
printf("\n");
}
return 0;
}
Re: Can't find error in Problem 160
"Presentation Error" here at UVa judge (but not at most other places) means that your answer is basically correct, but you have too few or too many blanks/newlines somewhere.
Read the output format section again, make sure that your program's output is exactly like sample output.
Read the output format section again, make sure that your program's output is exactly like sample output.
Re: 160 WA.................
#include<stdio.h>
int main() /***** WA *****/
{
int i,j,c,n,k,l;
int a[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 b[25];
while(scanf("%d",&n)!=EOF)
{
if(n==0)
{
break;
}
for(i=0;i<25;i++)
{
b=0;
}
l=n;
k=n;
c=0;
while(k>=2)
{
n=k;
for(i=0;i<25;i++)
{
if(n%a==0)
{
while(n>1)
{
if(n%a!=0)
{
break;
}
b++;
n=n/a;
}
}
if(n==1)
{
break;
}
}
if(i>c)
{
c=i;
}
k--;
}
printf("%3d! =",l);
for(j=0;j<=c;j++)
{
printf("%3d",b[j]);
if(j==14)
{
printf("\n ");
}
}printf("\n");
}
return 0;
}
int main() /***** WA *****/
{
int i,j,c,n,k,l;
int a[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 b[25];
while(scanf("%d",&n)!=EOF)
{
if(n==0)
{
break;
}
for(i=0;i<25;i++)
{
b=0;
}
l=n;
k=n;
c=0;
while(k>=2)
{
n=k;
for(i=0;i<25;i++)
{
if(n%a==0)
{
while(n>1)
{
if(n%a!=0)
{
break;
}
b++;
n=n/a;
}
}
if(n==1)
{
break;
}
}
if(i>c)
{
c=i;
}
k--;
}
printf("%3d! =",l);
for(j=0;j<=c;j++)
{
printf("%3d",b[j]);
if(j==14)
{
printf("\n ");
}
}printf("\n");
}
return 0;
}
Re: 160 - Factors and Factorials
Use 15 instead of 14 and give six blank space like as printf("\n ");
if(j==14)
{
printf("\n ");
}
try like this code:
if(j==15)
{
printf("\n ");
}
Finally check(give as input 1-100 at a time) and let me know...
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 0
if(j==14)
{
printf("\n ");
}
try like this code:
if(j==15)
{
printf("\n ");
}
Finally check(give as input 1-100 at a time) and let me know...
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 0