Code: Select all
I see thanks brianfry713
Moderator: Board moderators
Code: Select all
I see thanks brianfry713
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
Code: Select all
int main() {
long double p,n;
while (cin >> n >> p) {
cout << round(powl(p, (1.0/n))) << endl;
}
return 0;
}
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.brianfry713 wrote:pow(p, 1.0 / n)) is the same as the nth root of p.
P.S: Edited post and added link where the precision piece is clarified after finding that the question's already been addressed.double has enough precision for the I/O in the judge for this problem.
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;
}