【发布时间】:2011-02-22 11:21:25
【问题描述】:
我需要编写一个算法(我不能使用任何 3rd 方库,因为这是一个分配)来划分(整数除法,浮动部分不重要)非常大的数字,例如 100 - 1000 位。我找到了http://en.wikipedia.org/wiki/Fourier_division 算法,但我不知道这是否是正确的方法。你有什么建议吗?
1) check divisior < dividend, otherwise it's zero (because it will be an int division)
2) start from the left
3) get equal portion of digits from the dividend
4) if it's divisor portion is still bigger, increment digits of dividend portion by 1
5) multiply divisor by 1-9 through the loop
6) when it exceeds the dividend portion, previous multiplier is the answer
7) repeat steps 3 to 5 until reaching to the end
【问题讨论】:
-
“因为这是作业”...添加作业标签?
-
如果你能在纸上做长除法,你已经知道解决这个问题的好算法了。
-
@Neil:嗯,我不希望收到代码示例。我只是希望学习一些数学技巧来超越这些语言限制。
-
@pocoa:那么你应该添加 homework 标签。标签表示您需要帮助/想法/建议,但您不希望为您完成工作。
-
@Carl:我认为当您需要将 120 位数字除以 75 时,这并不容易 :) 这就是我问的原因。
标签: c++ algorithm math largenumber