113 - Power of Cryptography

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

Moderator: Board moderators

ibrahim
Experienced poster
Posts: 149
Joined: Mon Feb 07, 2005 10:28 pm
Location: Northern University, Bangladesh
Contact:

Re: Can anybody help me?

Post 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

Andrey
New poster
Posts: 16
Joined: Sat Mar 05, 2005 8:25 pm
Location: Ukraine,Vinnitsa

Post by Andrey »

It's number 113 :oops: [/b]

abhijit
New poster
Posts: 12
Joined: Mon May 24, 2004 2:13 pm

Post 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.

abhijit
New poster
Posts: 12
Joined: Mon May 24, 2004 2:13 pm

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

neno_uci
Experienced poster
Posts: 104
Joined: Sat Jan 17, 2004 12:26 pm
Location: Cuba

Post 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

abhijit
New poster
Posts: 12
Joined: Mon May 24, 2004 2:13 pm

Post 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.

asif_rahman0
Experienced poster
Posts: 209
Joined: Sun Jan 16, 2005 6:22 pm

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

Post 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

asif_rahman0
Experienced poster
Posts: 209
Joined: Sun Jan 16, 2005 6:22 pm

Post 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.

Gaolious
New poster
Posts: 28
Joined: Mon Nov 04, 2002 8:03 pm
Location: South Korea, Seoul
Contact:

prototype.

Post by Gaolious »

scanf( const char *format, ... );

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

so,

scanf("%lf", &p);

CDiMa
Experienced poster
Posts: 214
Joined: Fri Oct 17, 2003 5:49 pm
Location: Genova

Re: prototype.

Post 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

Dmitry R
New poster
Posts: 7
Joined: Sat Sep 17, 2005 10:42 am
Contact:

Post 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?

bidol
New poster
Posts: 7
Joined: Sun Jul 10, 2005 1:14 pm

about 'long' and 'long double'

Post 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?...
sorry, i'm not good at english.

asif_rahman0
Experienced poster
Posts: 209
Joined: Sun Jan 16, 2005 6:22 pm

Post 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.:)

bidol
New poster
Posts: 7
Joined: Sun Jul 10, 2005 1:14 pm

thanks~

Post by bidol »

you are right!

and i got accepted, with 'long double' .. ^^..
sorry, i'm not good at english.

subzero
New poster
Posts: 26
Joined: Mon Aug 15, 2005 5:21 am

Post 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.
There is no knowledge that is no power.

Post Reply

Return to “Volume 1 (100-199)”