Page 8 of 11

Re: Can anybody help me?

Posted: Sun Mar 13, 2005 8:40 pm
by ibrahim
Andrey wrote:

Code: Select all

#include<iostream.h>
#include<math.h>

void main()
{
  double n,p;
  while(cin>>n>>p) cout<<floor(pow(p,1.0/n)+0.5);
}
Thank's![/code]
I think output of both code is not same.
In the AC code you use " %.lf " which mean the output should be without any point.
But in the second code you don't tell any thing. So it should print point and so on.
:D
By the way, what's the number of this problem.

Ibrahim

Posted: Mon Mar 14, 2005 8:46 am
by Andrey
It's number 113 :oops: [/b]

Posted: Mon Mar 21, 2005 4:32 pm
by abhijit
don't use the @begin... and @end.... I hear they don't work too well.
More importantly, i guess they should be without the quotes, which is why you could be getting a compile error.

Try the Submit-o-matic.

Posted: Mon Mar 21, 2005 4:45 pm
by abhijit
I am shocked by the fact that this "C" code is AC if i include the math.h header file and is a WA if i do not. Don't believe me ? Try it out.
Can anyone explain this ? I find that pow and floor are both proper functions and not macros.

Code: Select all

#include<math.h>
int main(){
  double n,p;
  while(scanf("%lf %lf",&n,&p)==2){
    printf("%.0lf\n",floor(pow(p,1.0/n)+0.5));}
  return 0;
} 

Posted: Mon Mar 21, 2005 6:31 pm
by neno_uci
floor and pow are declared in the header file(math.h) , so if you try to use them without including math.h you will get a Compile Error, remember that the judge compiler is gcc...

best regards,
Yandry. :D

Posted: Tue Mar 22, 2005 12:48 pm
by abhijit
A) The header file math.h only has the prototypes for the functions, and not the definition. The function definitions are in binary in the library.

B) "C", i believe, doesn't necessarily ask you to specify prototypes before you call functions.

C) MOST IMPORTANT : My program DID NOT receive a compile error, but a WRONG ANSWER.


Hmm, could it be that if no prototype is specified, the compiler expects that the return type is int by default, and the actual return is ?cast? to an int.

Re: 113- power of cryptography - What is the algorithm?

Posted: Mon May 16, 2005 8:10 pm
by asif_rahman0
Hello laboni There is no algorithm needed to solve this problem.The formula that I used to solved the problem was
k=p^(1/n)
hope u can accept ur code.
BEST OF LUCK

Posted: Thu Jun 09, 2005 7:17 pm
by asif_rahman0
Hello ImLazy,as far as I know if u use TURBO C compiler and use double then the first 15/16 digits are correctly shown but the rest of the digits are 0's incase of more then 15/16 digits.U can solve the problem using Visual C++ compiler.

prototype.

Posted: Thu Jun 23, 2005 12:41 am
by Gaolious
scanf( const char *format, ... );

must be pointer variables like int* , char *, double*, in the "..."

so,

scanf("%lf", &p);

Re: prototype.

Posted: Thu Jun 23, 2005 9:54 am
by CDiMa
Gaolious wrote:scanf( const char *format, ... );

must be pointer variables like int* , char *, double*, in the "..."

so,

scanf("%lf", &p);
abhijit correctly used the address of integer variables in his scanf.

His problem was exactly answered by his followup.
In C undeclared functions are assumed to return int by the compiler. Without the #include of
math headers the pow function is assumed to return int and this caused the WA.

Ciao!!!

Claudio

Posted: Fri Jan 06, 2006 6:00 pm
by Dmitry R
Can you help me?
I tried to submit two programs. This one got AC:

/* Edited */
It is just like the second, but all the types are double instead of long double...

And this one got a WA:

Code: Select all

#include <stdio.h>
#include <math.h>

int main(void)
{
	long double n, p;
	while (scanf("%Lf %Lf", &n, &p) == 2)
		printf("%.0Lf\n", floor(pow(p, ((long double)1.0)/n) + 0.1));
	return 0;
}
Why?! I expected the long double computation to be at least not less precise than double... Or it is because of the truncation?

about 'long' and 'long double'

Posted: Sat Jul 08, 2006 3:17 pm
by bidol
in problem 113 'Power of Cryptography' ,

i code,

Code: Select all

	long double n, k, p; 
	
	while (cin >> n >> p) 
	{ 
		
		k = pow(p,(1/n)); 
		printf("%.0lf\n", k);		
	} 
and got WA. so~ so~ many times...
but,

Code: Select all

	double n, k, p; 
	
	while (cin >> n >> p) 
	{ 
		
		k = pow(p,(1/n)); 
		printf("%.0lf\n", k);		
	} 
this got accepted.

why?...

you know, #113 is 'big' number problem, so i think 'long double' is
more sutable than 'just double', becouse it is larger....

more larger data type is deeded in this problem, isn't?...
and... so...
'long double' is better than 'double' ..... right?...

Posted: Sat Jul 08, 2006 4:36 pm
by asif_rahman0
i think the right format is

Code: Select all

%lf for double 
%lf not for long double
%Lf for long double
hope you got it.:)

thanks~

Posted: Sat Jul 08, 2006 4:56 pm
by bidol
you are right!

and i got accepted, with 'long double' .. ^^..

Posted: Fri Sep 15, 2006 8:14 pm
by subzero
I think it is a little late to answer this topic... but.....if some one needs help:

first: n can be int, p can be double
second: you don't need floor

see ya.