160 - Factors and Factorials
Moderator: Board moderators
-
- Guru
- Posts: 5947
- Joined: Thu Sep 01, 2011 9:09 am
- Location: San Jose, CA, USA
Re: Presentation error on 160
Don't print a space at the end of a line.
Check input and AC output for thousands of problems on uDebug!
Re: Presentation error on 160
Thanks Guru! Brianfry
Re: Presentation error on 160
Thanks for the edge case Brian. And those getting runtime error - looks like input contains number greater than 100 as well.
Re: 160 - Factors and Factorials
Those getting runtime error, looks like input contains number greater than 100 so generate little extra primes.
-
- New poster
- Posts: 13
- Joined: Tue Jul 08, 2014 7:14 pm
Re: 160 - Factors and Factorials
I can't find my problem will you help me
here's my code
#include <iostream>
#include <stdio.h>
using namespace std;
int main()
{
long n,i,j,k,m;
while(cin>>n, n!=0)
{
long fac[25]={0},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};
for(i=2; i<=n; i++)
{
k=i;
while(k>=1)
{
for(j=2; j<=k; j++)
{
if(k%j==0)
{
for(m=0;m<25;m++)
{
if(j==prime[m])
{
fac[m]++;
break;
}
}
break;
}
}
k=k/j;
}
}
int count=0;
printf("%3d! =",n);
for(i=0;fac!=0;i++)
{
if(count==15)
printf("\n%6c",' ');
printf("%3d",fac);
count++;
}
printf("\n");
}
return 0;
}

#include <iostream>
#include <stdio.h>
using namespace std;
int main()
{
long n,i,j,k,m;
while(cin>>n, n!=0)
{
long fac[25]={0},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};
for(i=2; i<=n; i++)
{
k=i;
while(k>=1)
{
for(j=2; j<=k; j++)
{
if(k%j==0)
{
for(m=0;m<25;m++)
{
if(j==prime[m])
{
fac[m]++;
break;
}
}
break;
}
}
k=k/j;
}
}
int count=0;
printf("%3d! =",n);
for(i=0;fac!=0;i++)
{
if(count==15)
printf("\n%6c",' ');
printf("%3d",fac);
count++;
}
printf("\n");
}
return 0;
}
Re: 160 - Factors and Factorials
Input
Acc output
Your output
Don't forget to remove your code after getting accepted. 
Code: Select all
100
0
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
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 110012451124297438 1879047287917443473460340792421473239042147323904124515242638601245168

A person who sees the good in things has good thoughts. And he who has good thoughts receives pleasure from life... Bediuzzaman
-
- Guru
- Posts: 5947
- Joined: Thu Sep 01, 2011 9:09 am
- Location: San Jose, CA, USA
Re: 160 - Factors and Factorials
It looks like you figured it out.
Check input and AC output for thousands of problems on uDebug!
160 - Factors and Factorials why PE
Help Help.....
This code gives PresentationE
This code gives PresentationE
Last edited by NAbdulla on Fri Jan 23, 2015 6:39 am, edited 1 time in total.
-
- Guru
- Posts: 5947
- Joined: Thu Sep 01, 2011 9:09 am
- Location: San Jose, CA, USA
Re: 160 - Factors and Factorials
Next time post in the existing thread.
Look at the spacing in the sample output.
Look at the spacing in the sample output.
Check input and AC output for thousands of problems on uDebug!
-
- New poster
- Posts: 1
- Joined: Fri Sep 12, 2014 10:41 am
Re: 160 - Factors and Factorials
http://ideone.com/N6jRqA
what's wrong???
what's wrong???