Questions tagged [nth-root]

The nth-root of a number `x` is a number `r` such that `r` raised to the power of `n` equals `x`.

24 questions
32
votes
11 answers

How to compute the nth root of a very big integer

I need a way to compute the nth root of a long integer in Python. I tried pow(m, 1.0/n), but it doesn't work: OverflowError: long int too large to convert to float Any ideas? By long integer I mean REALLY long integers…
PiX
  • 9,705
  • 4
  • 19
  • 11
23
votes
10 answers

Calculating nth root in Java using power method

I was trying to get a cubic root in java using Math.pow(n, 1.0/3) but because it divides doubles, it doesn't return the exact answer. For example, with 125, this gives 4.9999999999. Is there a work-around for this? I know there is a cubic root…
Sara Alaa Khodeir
  • 349
  • 1
  • 3
  • 9
21
votes
2 answers

C# Find Nth Root

I use below method to calculate Nth Root of double value, but it takes a lot of time for calculating the 240th root. I found out about Newton method, but was not able to implement it into a method. Any help would be appreciated. static double…
illusion
  • 383
  • 2
  • 4
  • 9
19
votes
8 answers

nth root implementation

I am working on a way to calculate the nth root of a number. However, I am having problems with the nth root of negative numbers. Most people say to use Math.pow(num, 1 / root), but this does not work for negative numbers. I have tried this: public…
Will
  • 19,661
  • 7
  • 47
  • 48
17
votes
11 answers

How to find integer nth roots?

I want to find the greatest integer less than or equal to the kth root of n. I tried int(n**(1/k)) But for n=125, k=3 this gives the wrong answer! I happen to know that 5 cubed is 125. >>> int(125**(1/3)) 4 What's a better algorithm? Background:…
Colonel Panic
  • 132,665
  • 89
  • 401
  • 465
10
votes
5 answers

Precise nth root

I'm looking for Python Nth root function/algorithm but before you post: NO INTEGER ROOT, HELL! Where could I obtain at least a guide how to program Nth root function that produces precise float/Decimal? Such function that doesn't return 1 nor 0 for…
R.O.S.S
  • 605
  • 5
  • 18
7
votes
3 answers

integer nth root

x' is the nth root of y if x' is the largest integer such that x^n <= y. x, x' and y are all integers. Is there any efficient way to compute such nth root? I know this is usually done by nth root algorithm, but the difficulty here is everything is…
sinoTrinity
  • 1,125
  • 2
  • 15
  • 27
6
votes
4 answers

How to check if the number can be represented prime power (nth root is prime or not)

I am trying this problem for a while but getting wrong answer again and again. number can be very large <=2^2014. 22086. Prime Power Test Explanation about my algorithm: For a Given number I am checking if the number can be represented as form of…
Lakshman
  • 469
  • 5
  • 12
5
votes
2 answers

The fourth root of (12) or any other number in Python 3

I'm trying to make a simple code for power 12 to 4(12 ** 4) . I have the output num (20736) but when I want to figure returns (20736) to its original value (12). I don't know how to do that in Python .. in Real mathematics I do that by the math…
Mr Sam
  • 981
  • 1
  • 8
  • 12
4
votes
2 answers

how to use the nthroot function in R

I am trying to use the nthroot function from the pracma package. However, whenever I run it I get an error: Error in nthroot(x, 5) : could not find function "nthroot" I tried installing the pracma package but that didn't help either. Could anyone…
kronokrusader
  • 43
  • 4
  • 5
4
votes
3 answers

n-th Root Algorithm

What is the fastest way to calculate the n-th root of a number? I'm aware of the Try and Fail method, but I need a faster algorithm.
Alon Gubkin
  • 56,458
  • 54
  • 195
  • 288
2
votes
1 answer

Taking n-th root

What is the best way to take the n-th root of an arbitrary number in rust? The num crate for example only allows to take n-th principal roots of integer types, i.e., floor'ed or ceil'ed values... How to best closely approximate the actual value?
D3PSI
  • 154
  • 2
  • 11
2
votes
1 answer

How can I prevent the result from being a complex number? (Cube root of -27)

I've figured out the following solution (probably not that hard anyway): n1, n2 = -27, 3 root = ( n1 ** (1/n2)) print(root) (1.5000000000000004+2.598076211353316j) Unless I'm making a very dumb mistake, it should print -3 instead.
2
votes
1 answer

Calculating the n-th root of an integer using PHP/GMP

How can I calculate the n-th root of an integer using PHP/GMP? Although I found a function called gmp_root(a, nth) in the PHP source, it seems that this function has not been published in any release yet*: http://3v4l.org/8FjU7 *) 5.6.0alpha2 being…
ComFreek
  • 29,044
  • 18
  • 104
  • 156
1
vote
0 answers

N-th Root Upto 101 Significant Places

I'm required to determine the n-th(n is a positive 32-bit integer) root of a given floating point number x of arbitrary precision upto 101 significant places. My approach using Newton's method however gives me results upto 53 decimal places only.…
1
2