Page 9 of 14

Posted: Sat Jun 03, 2006 5:56 pm
by kwedeer
Thaks little joey now Accepted... But how could I know this?

Posted: Sun Jun 04, 2006 12:11 am
by little joey
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;

Posted: Sun Jun 18, 2006 8:02 am
by Rhododendron
Why you the guy's upload your code.Let us discuss about the algorithm.
If any one does not know how to use algorithm then he/she should leave
programming.

160 - RUNTIME ERROR!!

Posted: Wed Jun 21, 2006 9:17 pm
by TripShock
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.

Code: Select all

ACCEPTED!!

Posted: Thu Jun 22, 2006 8:58 pm
by asif_rahman0
Its ok that you got RTE.
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
Hope you now Clear :)

Posted: Thu Jun 22, 2006 9:55 pm
by TripShock
That's a really cool method! Thanks! But I still don't get why the oj flags runtime error for my original program!

Posted: Thu Jun 22, 2006 11:00 pm
by asif_rahman0
hope this will help you.
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;
}
Hope its Help.

Posted: Fri Jun 23, 2006 1:42 am
by TripShock
I don't know what but something about your sieve code is just SOO right, asif_rahman! thanks a lot! i don't know how but your code got my program accepted!

160

Posted: Fri Jul 21, 2006 4:13 pm
by abhi
hey this is my code for this simple problem ............. but i get TLE ..........
why ?????

Code: Select all


CODE DELETED after AC :)


160 - Dont Understand

Posted: Thu Aug 10, 2006 2:44 pm
by Donotalo
how does the first output for 53! is 49? probably i dont understand the representation. can anyone explain it to me?

Posted: Mon Aug 14, 2006 10:09 pm
by nev4
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?

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;
}

Posted: Wed Aug 16, 2006 5:42 am
by kolpobilashi
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.


Code: Select all

removed
maybe the mistake is silly...but in return wat i'm getting is not so silly...
so thanx in advance

Posted: Wed Aug 16, 2006 10:59 am
by mamun

Code: Select all

printf("\n      ");
Above statement will be executed for any N. But it should be executed for those only whose factorial have more than 15 prime factors.

Posted: Wed Aug 16, 2006 4:28 pm
by kolpobilashi
thanx a lt bro...the mistake is in the 2nd for loop condition....how cud i be so stupid :oops:

thanx again. :)

ACM 160 I get WA many time , I do not Why, please healp me

Posted: Thu Aug 24, 2006 7:06 pm
by srabon
code deleted