作者arrenwu (最是清楚哇她咩)
看板Math
标题Re: 一题很难又很简单的数学题
时间Sun Mar 17 22:50:40 2024
※ 引述《JauJu (教主)》之铭言:
: 题目 找到一组A*B约等於704290
: A接近2111且必须是正整数
: B可以到小数第二位
: A*B的答案,乘积如果有小数可以四舍五入变成整数,乘积四舍五入後要等於704290
: (只有小数点後可以四舍五入)
: 如何找到一组A跟B能符合答案
: 如果能写成excel计算更好了
: 求大神解答
乘积四舍五入後要等於704290:
704289.5 <= A*B < 704290.5 ...... (1)
B可以到小数第二位: 那麽B 就会试某一个正整数K 除以100
也就是 B = K/100 ......(2)
最後加上
A接近2111且必须是正整数 ..... (3)
这问题可以写成一个最佳化的问题
min |A-2111|
subject to: A,K 正整数
70428950 <= A*K < 70429050
Excel 我不知道你会打算怎麽做,但是Python可以这样做
import math
target = 2111
d = 0
lower_bound = 70428950
upper_bound = 70429050
found = False
while (d < target):
for candidate in [target-d, target+d]:
A = candidate
K = math.ceil(lower_bound/A)
if A*K < upper_bound:
print('A = {}, B = {}'.format(A, K/100))
found = True
break
if found:
break
d += 1
我找到的最接近 2111 的
A = 2142, B = 328.8
--
早川秋看到的未来
https://i.imgur.com/aRFJqId.jpg
https://i.imgur.com/SXPvXGe.jpg
--
※ 发信站: 批踢踢实业坊(ptt.cc), 来自: 98.45.195.96 (美国)
※ 文章网址: https://webptt.com/cn.aspx?n=bbs/Math/M.1710687042.A.B17.html
1F:推 cuteSquirrel: 羊羊人真好~ 03/17 22:55
2F:推 LPH66 : [target-d, target-d] # 应该要 +d 吧? 03/17 23:03
没错 是我程式写错了XD 更新一下
※ 编辑: arrenwu (98.45.195.96 美国), 03/17/2024 23:05:22