160 - Factors and Factorials
Moderator: Board moderators
-
- Guru
- Posts: 1080
- Joined: Thu Dec 19, 2002 7:37 pm
I don't know. I think on unix systems the newline is used as a line terminator rather than as line separator, which means that all lines, including the last, should end with a newline; my linux compiler complains if my source doesn't end in a newline, but my DOS compiler doesn't.
Anyway, just always terminate your lines, and if the output format specifies that you should print a blank line after the last case (some problems do that), just use an extra writeln:
writeln(last line of output);
writeln;
Anyway, just always terminate your lines, and if the output format specifies that you should print a blank line after the last case (some problems do that), just use an extra writeln:
writeln(last line of output);
writeln;
-
- New poster
- Posts: 1
- Joined: Sun Jun 18, 2006 7:34 am
160 - RUNTIME ERROR!!
this code works for all test cases on my pc, but with oj it give runtime error floating point exception! somebody please help!
info:
i use sieve of eratosthenes to compute all prime nos >=2 <= 100.
info:
i use sieve of eratosthenes to compute all prime nos >=2 <= 100.
Code: Select all
ACCEPTED!!
Last edited by TripShock on Fri Jun 23, 2006 1:42 am, edited 1 time in total.
-
- Experienced poster
- Posts: 209
- Joined: Sun Jan 16, 2005 6:22 pm
Its ok that you got RTE.
But if you use formula then you must get accepted:).
Hope you now Clear 
But if you use formula then you must get accepted:).
Code: Select all
Highest Power of a prime (P) which divides (n!) is
floor(n/p)+floor(n/p^2)+floor(n/p^3) +........+floor(n/p^h)
where p=2,3,5,7....etc
so you can do it easily with repeated division like 10!.
10/2=5
5/2=2
2/2=1

-
- Experienced poster
- Posts: 209
- Joined: Sun Jan 16, 2005 6:22 pm
hope this will help you.
This is my SIEVE CODE. You define ur array Size.ok.
Hope its Help.
This is my SIEVE CODE. You define ur array Size.ok.
Code: Select all
int p[SIZE];
int k;
void prime(long SIZE)
{
int i,j;
bool *pr=new bool[SIZE+10];
for(i=2;i<=MAX;i++){pr[i]=true;}
for(i=2;i<=MAX;i++){if(!pr[i]) continue;for(j=i+i;j<=MAX;j+=i){pr[j]=false;}}
k=0;
for(i=2;i<=MAX;i++){if(pr[i]){p[k++]=i;}}
delete [] pr;
}
160
hey this is my code for this simple problem ............. but i get TLE ..........
why ?????
why ?????
Code: Select all
CODE DELETED after AC :)
160 - Dont Understand
how does the first output for 53! is 49? probably i dont understand the representation. can anyone explain it to me?

825 could be specified as (0 1 2 0 1) meaning no twos, 1 three, 2 fives, no sevens and 1 eleven.
This problem is so easy to solve, but I don't know why WA, even if I think it works just fine. Anyone can help me?
This problem is so easy to solve, but I don't know why WA, even if I think it works just fine. Anyone can help me?
Code: Select all
#include <iostream>
#include <vector>
#include <iterator>
#include <cmath>
#include <iomanip>
using namespace std;
int rez[99]; // times of primes
int main()
{
vector<int> primes;
primes.push_back(2);
primes.push_back(3);
vector<int>::iterator it;
for(int i = 5; i < 100; i++)
{
for(it = primes.begin(); it != primes.end(); ++it)
{
if(i % *it == 0)
{
break;
}
}
if(it == primes.end())
{
primes.push_back(i);
}
}
int n;
cout.setf(ios::right);
while(cin >> n)
{
if(n == 0)
{
return 0;
}
for(int i = 0; i < 99; i++)
{
rez[i] = 0;
}
for(int i = 2; i <= n; i++)
{
int j = i;
for(it = primes.begin(); *it <= n; ++it)
{
while(j % *it == 0)
{
++rez[*it];
j /= *it;
}
if(j == 1)
{
break;
}
}
}
cout << setw(3) << n << "! =";
int count = 0;
for(it = primes.begin(); *it <= n; ++it)
{
if(count % 15 == 0 && count)
{
cout << endl << setw(9) << rez[*it];
}
else
{
cout << setw(3) << rez[*it];
}
++count;
}
cout << endl;
}
return 0;
}
-
- Learning poster
- Posts: 54
- Joined: Mon Jan 02, 2006 3:06 am
- Location: Dhaka,Bangladesh
- Contact:
sorry to bother again.......
got WA but hav no idea whyyyyyy????
everything seems to be so perfect..read all prev threads too and thus got sure abt my output format....then where is the mistake?can any1 say
i'm getting frustrated.
maybe the mistake is silly...but in return wat i'm getting is not so silly...
so thanx in advance

everything seems to be so perfect..read all prev threads too and thus got sure abt my output format....then where is the mistake?can any1 say

i'm getting frustrated.
Code: Select all
removed
so thanx in advance
Last edited by kolpobilashi on Wed Aug 16, 2006 4:30 pm, edited 1 time in total.
Sanjana
Code: Select all
printf("\n ");
-
- Learning poster
- Posts: 54
- Joined: Mon Jan 02, 2006 3:06 am
- Location: Dhaka,Bangladesh
- Contact:
ACM 160 I get WA many time , I do not Why, please healp me
code deleted
Last edited by srabon on Tue Aug 29, 2006 6:44 am, edited 1 time in total.