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

darksk4
New poster
Posts: 13
Joined: Sun Jul 29, 2012 7:10 pm

Re: 113 - wrong answer

Post by darksk4 » Fri Nov 02, 2012 7:45 pm

What's the error in this code?

Code: Select all

I see thanks brianfry713 
Last edited by darksk4 on Sat Nov 03, 2012 1:20 pm, edited 2 times in total.

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

Re: 113 - wrong answer

Post by brianfry713 » Fri Nov 02, 2012 9:36 pm

You need to set the precision so that only integers are displayed.
Check input and AC output for thousands of problems on uDebug!

salman2972
New poster
Posts: 1
Joined: Tue Jun 18, 2013 1:52 am

Re: 113 precision

Post by salman2972 » Tue Jun 18, 2013 2:00 am

i tried to solve that problem in matlab it worked!!!

Code: Select all

clear all
close all
clc

%round;ceil;floor;
y=7;
x=4357186184021382204544;
n=4;
p=16;

% check if the n or p in float type then exit

con1=((n-floor(n))&&(n-floor(n)));
con2=((p-floor(p))&&(p-floor(p)));
if(~(con1&&con2))
k=exp(log(p)/n);
%round(k)
else
    disp('the inputs must be the intiger values')
end


con3=((k-floor(k))&&(k-floor(k)));

if(~con3)
    k
else
    disp('the value of k is not an intiger  please try another combination')
end
please let me know if i can make it better...

caiomcg
New poster
Posts: 3
Joined: Tue Oct 29, 2013 4:30 pm

113 - Precision - Time limit exceeded

Post by caiomcg » Tue Oct 29, 2013 4:35 pm

Hey guys.

I am having a problem in the time limit.
Can you guys have a look?
Probably not the best code ;)

http://pastebin.com/m2tEjeEM

Thanks

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

Re: 113 - Precision - Time limit exceeded

Post by brianfry713 » Tue Oct 29, 2013 9:59 pm

Output pow(p, 1.0 / n));
Check input and AC output for thousands of problems on uDebug!

caiomcg
New poster
Posts: 3
Joined: Tue Oct 29, 2013 4:30 pm

Re: 113 - Precision - Time limit exceeded

Post by caiomcg » Wed Oct 30, 2013 2:00 pm

Thank You!

But, I don´t understand this expression, can you explain it to me?

Regards

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

Re: 113 - Precision - Time limit exceeded

Post by brianfry713 » Wed Oct 30, 2013 7:47 pm

pow(p, 1.0 / n)) is the same as the nth root of p.
Check input and AC output for thousands of problems on uDebug!

caiomcg
New poster
Posts: 3
Joined: Tue Oct 29, 2013 4:30 pm

Re: 113 - Precision - Time limit exceeded

Post by caiomcg » Thu Oct 31, 2013 1:35 pm

I got it lol, thank you Brian!

arash
New poster
Posts: 6
Joined: Wed Feb 19, 2014 10:19 am

Re: 113 - Precision - Time limit exceeded

Post by arash » Thu Feb 20, 2014 2:45 pm

why I get wa by this code ?

Code: Select all

int main() {
    long double p,n;
    while (cin >> n >> p) {
        cout << round(powl(p, (1.0/n))) << endl;
    }
    return 0;
}

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

Re: 113 - Precision - Time limit exceeded

Post by brianfry713 » Thu Feb 20, 2014 11:21 pm

cout << (int)round(powl(p, (1.0/n))) << endl;
Check input and AC output for thousands of problems on uDebug!

User avatar
uDebug
A great helper
Posts: 475
Joined: Tue Jul 24, 2012 4:23 pm

Re: 113 - Precision - Time limit exceeded

Post by uDebug » Fri Mar 14, 2014 1:41 pm

brianfry713 wrote:pow(p, 1.0 / n)) is the same as the nth root of p.
Right. So I came to the same conclusion before I looked at this thread but then I'm not sure how to go about doing this because p could be as large as 10^100 - and so surely a long double's not going to be able to store p. It occurred to me that I could employ BigInt in Java but the pow function doesn't allow for doubles in the exponent - just ints.

Did I miss something?

Update:

Looks like, foo asked the same question in the following thread here

http://acm.uva.es/board/viewtopic.php?f ... 8d#p205142

brianfry713's reply in that thread is
double has enough precision for the I/O in the judge for this problem.
P.S: Edited post and added link where the precision piece is clarified after finding that the question's already been addressed.
Check input and AC output for over 7,500 problems on uDebug!

Find us on Facebook. Follow us on Twitter.

liya
New poster
Posts: 10
Joined: Fri Jan 23, 2015 2:36 pm

Re: 113 - Power of Cryptography

Post by liya » Wed Jan 28, 2015 10:17 pm

WA.....

Code: Select all

#include<stdio.h>
#include<math.h>
int main()
{
  double n,p,k;

while((scanf("%lf %lf",&n,&p))!=EOF)
{
k=pow(p,(1.0/n));
printf("%.0lf\n",k);

}
return 0;


}
Last edited by brianfry713 on Wed Jan 28, 2015 10:58 pm, edited 1 time in total.
Reason: Added code blocks

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

Re: 113 - Power of Cryptography

Post by brianfry713 » Thu Jan 29, 2015 1:16 am

That is AC code.
Check input and AC output for thousands of problems on uDebug!

Post Reply

Return to “Volume 1 (100-199)”