0

I need to be able to do 1938757289258398239399949292934/14583949053930202 without using any external java functions or libraries. I have each digit of my numbers stored in a linked list. What else can I do?

Can someone help me divide an algorithm. I've been trying at it for a few hours now and i'm not getting anywhere.

3
  • Does BigInteger count as "external"? Commented Feb 24, 2012 at 22:26
  • 2
    This is just long division using two lists of digits in a computer instead of two lists of digits written on paper. Commented Feb 24, 2012 at 22:27
  • Assuming subtraction, you can do digital division. Commented Feb 24, 2012 at 22:43

1 Answer 1

4

"External" Java libraries? (BigInteger is built-in, if you can use that.)

Otherwise, the simplest approach to division is probably binary, as follows. You know that log(a/b) = log(a) - log(b), so you have an estimate on the number of bits in the result. Let r be the result. In pseudocode,

for i = the most significant bit the result could have, iterating down to 0
  if (r + 2^i) * b <= a
    r += 2^i
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.