给定十进制数,找到给出整数结果的最小整数乘数 [英] Given a decimal number, find the smallest integer multiplier that gives an integer result
本文介绍了给定十进制数,找到给出整数结果的最小整数乘数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
最好使用示例来描述问题.可以说我有一个十进制值100.227273.
Best to use an example to describe the problem. Lets say I have a decimal value 100.227273.
100.227273 * X = Y
100.227273 * X = Y
我需要找到给出整数Y的最小正整数X.
I need to find the smallest positive integer X that gives integer Y.
推荐答案
如果100.227273只是一个近似值,并且您想要获得最佳有理近似值,请使用
If the 100.227273 is just an approximation and you want to get the best rational approximation, use continued fractions.
以100.227273为例.
Take 100.227273 as example.
- 取整数部分(100).现在您得到100.227273 = 100 + 0.227273.
- 将0.227273取反得到4.39999(4.4?).
- 重复步骤1,直到您对错误满意为止.
所以你得到
1
100.227273 = 100 + —————————
1
4 + —————
1
2 + —
2
将此表达式简化为2205/22.
Simplify this expression to get 2205/22.
[编者注:有关示例代码,请参见此答案.]
这篇关于给定十进制数,找到给出整数结果的最小整数乘数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文