10219 - Find the ways !

All about problems in Volume 102. If there is a thread about your problem, please use it. If not, create one with its number in the subject.

Moderator: Board moderators

yogeshgo05
New poster
Posts: 47
Joined: Sun Nov 27, 2005 12:43 pm

Post by yogeshgo05 »

hi,

uva g++ compilers are little compact in header files & also this compiler
does not pull some header file if not included as in normal windows compilers ...

are the functions ecvt() ,gcvt() ... converting double to string are present in uva compiler
........
mf
Guru
Posts: 1244
Joined: Mon Feb 28, 2005 4:51 am
Location: Zürich, Switzerland
Contact:

Post by mf »

When I submit a C program, which calles [fge]cvt(), it compiles, so I guess, the answer to your question should be "yes".
But I have no idea, why the same program, submitted as a C++ source doesn't compile.

You can use sprintf() to convert double to a string instead.
yogeshgo05
New poster
Posts: 47
Joined: Sun Nov 27, 2005 12:43 pm

Post by yogeshgo05 »

yes i think its better of using sprintf in order to convert double to string
but there is other logic i suppose ie
log(n)+1 gives number of digits of number n .. i want to no brother
that is this logic works :wink:

any way thanks man.....
tmdrbs6584
Learning poster
Posts: 98
Joined: Sat Jan 21, 2006 12:45 pm
Location: Busan,Corea(Republic of)

1

Post by tmdrbs6584 »

Hi logic
Bye logic
Donotalo
Learning poster
Posts: 56
Joined: Sat Aug 20, 2005 11:05 am
Location: Bangladesh

10219 - number of digits

Post by Donotalo »

please help me! how to calculate number of digits of the result n*m? where n and m are integers.
Image
Observer
Guru
Posts: 570
Joined: Sat May 10, 2003 4:20 am
Location: Hong Kong

Post by Observer »

Use logarithms ?! :wink:
7th Contest of Newbies
Date: December 31st, 2011 (Saturday)
Time: 12:00 - 16:00 (UTC)
URL: http://uva.onlinejudge.org
Towhid
New poster
Posts: 38
Joined: Wed May 28, 2003 5:30 pm
Location: Bangladesh
Contact:

What is the Range

Post by Towhid »

Can anyone tell me the maximum value for n??????? :o
From 0 to 0
helloneo
Guru
Posts: 516
Joined: Mon Jul 04, 2005 6:30 am
Location: Seoul, Korea

Re: What is the Range

Post by helloneo »

Towhid wrote:Can anyone tell me the maximum value for n??????? :o
I don't know.. but possibly very big.. but surely fit in 32bit signed integer..
asif_rahman0
Experienced poster
Posts: 209
Joined: Sun Jan 16, 2005 6:22 pm

Post by asif_rahman0 »

HINTS:
think about log. We can find the number of digit by log(10 base, not ln).
Ex: if log(12334), then we get 4.
Finally the formula will be

Code: Select all

floor(log[n])+1.
himanshu
New poster
Posts: 17
Joined: Mon May 15, 2006 12:24 pm
Location: Hyderabad, India
Contact:

Post by himanshu »

The judge gives me Run Time Error for the following code :-

Code: Select all

#include<iostream>
#include<cmath>
#include<vector>

using namespace std;

long double logNfactorial(unsigned long int n)
{
    //static to reuse past stored results 
    static vector<long double> logNf(2, 0);

    for(int i = logNf.size(); i <= n; i++)
        logNf.push_back(logNf[i-1] + log10(i));
    return logNf[n];
}

int main()
{
    unsigned long int n, k;
    while(cin >> n >> k)
        cout << (unsigned long int)
                ceil(logNfactorial(n)-logNfactorial(k)-logNfactorial(n-k))
             << endl;
    return 0;
}
For a large value I get Abort as output

Code: Select all

% ./a.out 
999999 999
3430
99999999 9999
Abort
rio
A great helper
Posts: 385
Joined: Thu Sep 21, 2006 5:01 pm
Location: Kyoto, Japan

Post by rio »

I think the static vector is causing memory over flow or something.
Anyway, you don't need the vector at all.

----
Rio
pipo
New poster
Posts: 47
Joined: Tue May 11, 2004 6:43 pm
Location: Republic of Korea

Re: 10219 - Find the Ways !

Post by pipo »

hi..

I got WA several times.. but I don't really know... why WA ?? help me please..

Code: Select all

cutted after AC.. 
I just replaced data type from double to long double...  :-? 
thanks in advance...
@mjad
New poster
Posts: 44
Joined: Thu Jul 22, 2010 9:42 am

10219 why time limit exit ?help me pleaseeeee

Post by @mjad »

Code: Select all


#include<iostream.h>
///using namespace std;
unsigned long int fact(int n);
int main()
{
	int result[10000],carry,n,index;

    while(cin>>n)
	{
	     cout<<"\n";
		if(n>1000)
		   continue;
	cout<<fact(n)<<"\n\n";
	}


	 return 0;

}

unsigned long int fact(int n)
{

	int result[10000],carry,index;
	unsigned long int sum=0;
		result[0]=1;
		index=carry=0;
		if(n>1)
		{
			for(int i=2;i<=n;i++)
			{
				for(int j=0;j<=index;j++)
				{
				carry+=result[j]*i;
				result[j]=carry%10;
				carry/=10;

				}
				if(carry!=0)
				{
				   do
				   {
					   result[++index]=carry%10;
					   carry/=10;
				   }while(carry!=0);
				}
			}
		}

		   //cout<<n<<"! \n";
		   for(int i=index;i>=0;i--)
		   {
			 //cout<<result[i];
			 sum+=result[i];
		   }

	   //cout<<"\n";
	    return sum;

}
most of the problem, i get time limit exit please help me
about TLE please
Last edited by @mjad on Sat Jul 31, 2010 12:40 pm, edited 1 time in total.
sohel
Guru
Posts: 856
Joined: Thu Jan 30, 2003 5:50 am
Location: New York

Re: 10219 why time limit exit ?help me pleaseeeee

Post by sohel »

Why are you creating new threads for a problem whose discussions already exists!!
Don't create a new thread. Make your post in an existing one.

--and also use Code tags, when posting your code.
@mjad
New poster
Posts: 44
Joined: Thu Jul 22, 2010 9:42 am

Re: 10219 why time limit exit ?help me pleaseeeee

Post by @mjad »

thanks for reply..
i am really sorry for mistake,
after all i am a new user
no such mistake would happen in future

now help me please
Post Reply

Return to “Volume 102 (10200-10299)”