【发布时间】:2016-01-22 13:55:44
【问题描述】:
我已经开始研究 Java 中的一些编码问题,但被困在了两者之间。问题如下图所示。我们选择了一个数字作为除数,它的最后一位数字是 3;例如,3、13、33、203 等。现在,我们需要找到可以被除数除以的最低可能被除数,并且它的所有数字都是 1。例如:
we have a divisor as 3 so least dividened will be 111 only.
If we have divisor as 3 and choose divided as 1 then 1%3 !=0
If we have divisor as 3 and choose divided as 11 then 11%3 !=0
If we have divisor as 3 and choose divided as 111 then 111%3 ==0
So 111 will be least dividend which can be divided by 3.
现在,我开发了一些代码,当它包含在 Java 数据类型的范围内时,它可以找到最低的被除数。问题是当我们必须找到一个超出这个范围的红利时。例如:我们有 643 作为除数,我们需要找到能被 643 整除的最低被除数(只有 1)。
如果您能给我一些建议,我非常感谢您的帮助。
【问题讨论】:
-
到目前为止你有什么收获?
-
当
long不够大时,听起来你需要使用BigInteger。 -
注意一些输入,例如
10没有解。您应该计算出您可能需要考虑的 1 的数量是否有上限。 -
您是否只需要一个以任意大小执行此任务的蛮力算法?
标签: java performance data-structures types