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

@mjad
New poster
Posts: 44
Joined: Thu Jul 22, 2010 9:42 am

113 why not AC?

Post by @mjad »

please help me

Code: Select all


#include<math.h>
#include<iostream>
using namespace std;
int main()
{
   long double f,s,t;
   //freopen("in.txt","r",stdin);
   while(scanf("%lf%lf",&f,&s)==2)
   {
      t=exp(log(s)/f);
      printf("%.0lf\n",t);
   }
   return 0;
}

Hobby
New poster
Posts: 4
Joined: Thu Jul 29, 2010 2:35 pm

Re: 113 whats my problem? please help me

Post by Hobby »

please :
printf("%ld",...)

@mjad
New poster
Posts: 44
Joined: Thu Jul 22, 2010 9:42 am

Re: 113 whats my problem? please help me

Post by @mjad »

thanks hobby
but i did not get AC
it always WA
please help me, Specific way?

shaon_cse_cu08
New poster
Posts: 50
Joined: Tue May 25, 2010 9:10 am
Contact:

Re: 113 whats my problem? please help me

Post by shaon_cse_cu08 »

There is no problem in outputting with "%.0f" .... Just take a look at the problem carefully...

"For all such pairs 1<=n<=200 and the other condition's ...."

Try this input....

-4
16
0
56
0
0

Ur program alsways generates... 1 or 0 for this cases.... there will be no output for this

To test ur input and output try "http://uvatoolkit.com/"...

Hope That works... And don't open new Thread....if there is already one.....PLZZZ :D
I'll keep holding on...Until the walls come tumbling down...And freedom is all around ..... :x

zobayer
Experienced poster
Posts: 110
Joined: Tue May 06, 2008 2:18 pm
Location: CSE-DU, Bangladesh
Contact:

Re: 113 why not AC?

Post by zobayer »

You got WA because your solution is not correct, (I guess precision error)
For double data types, try to minimize the level of computation as more calculation will give you more errors.
You should not always say what you know, but you should always know what you say.

shaon_cse_cu08
New poster
Posts: 50
Joined: Tue May 25, 2010 9:10 am
Contact:

Re: 113 why not AC?

Post by shaon_cse_cu08 »

I Have already given its ans in ur previous tread and again u r opening a new tread... See ur previous post.... !!! :-? :-? :-?
I'll keep holding on...Until the walls come tumbling down...And freedom is all around ..... :x

Trarex
New poster
Posts: 3
Joined: Sun Dec 26, 2010 3:34 am

Re: 113 why not AC?

Post by Trarex »

Can someone say me about mistakes in my code? There should not be any problems with vars range (I've used float and double). So where can the problem hide?

Code: Select all

#include <iostream>
#include <math.h>
using namespace std;
int main()
{
    float n;
    double p;
    while (cin >> n >> p) cout << exp(log(p) / n) << endl;
    return 0;
}
Lately I modified the code in the next way:

Code: Select all

#include <iostream>
#include <math.h>
using namespace std;
int main()
{
    float n;
    double p;
    while (cin >> n >> p) cout << long(exp(log(p)/n)) << endl;
    return 0;
}
What is wrong? :-?

sir. manuel
New poster
Posts: 18
Joined: Sat Nov 20, 2010 7:44 pm

Re: 113 why not AC?

Post by sir. manuel »

try with pow(p,1/n)

Trarex
New poster
Posts: 3
Joined: Sun Dec 26, 2010 3:34 am

Re: 113 why not AC?

Post by Trarex »

WA ;(

Code: Select all

#include <iostream>
#include <math.h>
using namespace std;
int main()
{
    float n;
    double p;
    cout.precision(0);
    //while (cin >> n >> p) cout << long(exp(log(p)/n)) << endl;
    while (cin >> n >> p) cout << long(pow(p,1/n)) << endl;
    return 0;
}

sir. manuel
New poster
Posts: 18
Joined: Sat Nov 20, 2010 7:44 pm

Re: 113 why not AC?

Post by sir. manuel »

Code: Select all

#include<stdio.h>
#include<math.h>
int main()
{
double a,b;
while(scanf("%lf %lf",&a,&b)==2){
                                printf("%.0lf\n",pow(b,1/a));
                                } 
return 0;
}
Always use double!!!

Trarex
New poster
Posts: 3
Joined: Sun Dec 26, 2010 3:34 am

Re: 113 why not AC?

Post by Trarex »

and your solution has been accepted?

I've tried this one, but still WA

Code: Select all

#include <iostream>
#include <math.h>
using namespace std;
int main()
{
    //float n;
    double n,p;
    cout.precision(0);
    //while (cin >> n >> p) cout << long(exp(log(p)/n)) << endl;
    while (cin >> n >> p) cout << long(pow(p,1/n)) << endl;
    return 0;
}

foo
New poster
Posts: 1
Joined: Thu May 17, 2012 9:44 pm

113 precision

Post by foo »

Hi,
I just did problem '113 - Power of Cryptography', using the simple pow(p, 1/n) technique.
Though I don't quite see how this can be correct, as <= p <= 10^101 .
Isn't this too big for a double? For ex in java:
double d = Double.parseDouble("4357186184021382204544");
System.out.println(d); // outputs 4.357186184021382E21, major precision loss?

So shouldn't taking the square root of this number then give an incorrect answer?

thanks

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 113 precision

Post by brianfry713 »

double has enough precision for the I/O in the judge for this problem.

You are only taking the square root if n is 2.
Check input and AC output for thousands of problems on uDebug!

BlâckFoX
New poster
Posts: 1
Joined: Thu Aug 09, 2012 5:17 pm

113 - wrong answer

Post by BlâckFoX »

Hii can anyone help me?

I submitted this ,but the judge kept saying i have wrong answer =( please help
#include <iostream>
#include <math.h>
using namespace std;

int main(){
double n, p;
double ans;
while(cin >> n >> p){
ans= pow(p,1/n);
cout << round(ans) << endl;
}
return 0;
}

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 113 - wrong answer

Post by brianfry713 »

Try printing only the integer portion instead of using round().
Check input and AC output for thousands of problems on uDebug!

Post Reply

Return to “Volume 1 (100-199)”