Re: [問卦] 表妹問我一題國中數學 怎麼解?
※ 引述《renna038766 (微積分好難過)》之銘言:
: 表妹傳給我一題國中數學
: 題目很簡單,a、b 、c都是整數
: a + b + c = 8
: a^3 + b^3 + c^3 = 8
: 求a b c各是多少
: 我數學很爛 想半天都不會 向各位求救!
: -----
: Sent from JPTT on my iPhone
本魯只會寫程式
所以只好用窮舉法了
不用說上code
(Lua 這個網站自動幫你跑 https://www.lua.org/cgi-bin/demo )
local function PNNumber(n)
if n % 2 == 1 then
return (n + 1) / 2
else
return -n / 2
end
end
local counter = 0
local function Match(ta, tb, tc, cube)
local a = PNNumber(ta)
local b = PNNumber(tb)
local c = PNNumber(tc)
counter = counter + 1
if a + b + c == 8 and a * a * a + b * b * b + c * c * c == 8 then
print(string.format("a = %d b = %d c = %d counter = %d cube = %d", a,
b, c, counter, cube))
return true
end
return false
end
local function main(max)
for cube = 1, max do
for ta = 0, cube do
for tb = 0, cube do
if Match(ta, tb, cube, cube) then
return
end
end
end
-- 底下的其實不用計算,因為是重複的
for ta = 0, cube do
for tc = 0, cube - 1 do
if Match(ta, cube, tc, cube) then
return
end
end
end
for tb = 0, cube - 1 do
for tc = 0, cube - 1 do
if Match(cube, tb, tc, cube) then
return
end
end
end
end
end
main(100)
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 61.220.176.158 (臺灣)
※ 文章網址: https://www.ptt.cc/bbs/Gossiping/M.1648778838.A.949.html
噓
04/01 10:08,
2年前
, 1F
04/01 10:08, 1F
所以說本魯阿,其實只是要試試看窮舉法要花多少次而已
※ 編輯: elcnick (61.220.176.158 臺灣), 04/01/2022 10:14:27
→
04/01 10:15,
2年前
, 2F
04/01 10:15, 2F
腳本語言,寫遊戲常用到,RO就是用這個寫的
※ 編輯: elcnick (61.220.176.158 臺灣), 04/01/2022 10:17:49
※ 編輯: elcnick (61.220.176.158 臺灣), 04/01/2022 10:23:34
→
04/01 10:28,
2年前
, 3F
04/01 10:28, 3F
→
04/01 10:28,
2年前
, 4F
04/01 10:28, 4F
→
04/01 10:29,
2年前
, 5F
04/01 10:29, 5F
這倒不一定,但是基本上都難找到特殊規則
找到你都可以成為歷史數學家了
要如何優化你的暴力演算法也是門學問
推
04/01 10:42,
2年前
, 6F
04/01 10:42, 6F
※ 編輯: elcnick (61.220.176.158 臺灣), 04/01/2022 13:05:13
討論串 (同標題文章)