练习四十二:五家共井
五家共井,甲二绠(汲水用的井绳)不足,如(接上)乙一绠;
乙三绠不足,如丙一绠;
丙四绠不足,如丁一绠;
丁五绠不足,如戊一绠;
戊六绠不足,如甲一绠,皆及
先来翻译下再思考:
五家人公用一口井
甲家用绳子2条不够,需要加上乙家绳子1条才可打到井水
乙家用绳子3条不够,需要加上丙家绳子1条才可打到井水
丙家用绳子4条不够,需要加上丁家绳子1条才可打到井水
丁家用绳子5条不够,需要加上戊家绳子1条才可打到井水
戊家用绳子6条不够,需要加上甲家绳子1条才可打到井水
那么,就有公式了
甲*2+乙 = 乙*3+丙 = 丙*4+丁 = 丁*5+戊 = 戊*6+甲 = deep(井深)
用a,b,c,d,e分别表示
e = (deep-a)/6
d = (deep-e)/5=(5*deep+a)/30
c = (deep-d)/4=(25*deep-a)/120
b = (deep-c)/3=(95*deep+a)/360
deep = 2*a+b=721*a/265
1 for deep in range(1,10000): #随井深的变化会有变化 2 for a in range(1,10000): 3 if deep == 721*a/265: 4 b = (95*deep+a)/360 5 e = (deep-a)/6 6 d = (5*deep+a)/30 7 c = (25*deep-a)/120 8 print("井深:{},甲家绳长:{},乙家绳长:{},丙家绳长:{},丁家绳长:{},戊家绳长:{}".format(deep,a,b,c,d,e)) 9
执行结果:
井深:721,甲家绳长:265,乙家绳长:191.0,丙家绳长:148.0,丁家绳长:129.0,戊家绳长:76.0 井深:1442,甲家绳长:530,乙家绳长:382.0,丙家绳长:296.0,丁家绳长:258.0,戊家绳长:152.0 井深:2163,甲家绳长:795,乙家绳长:573.0,丙家绳长:444.0,丁家绳长:387.0,戊家绳长:228.0 井深:2884,甲家绳长:1060,乙家绳长:764.0,丙家绳长:592.0,丁家绳长:516.0,戊家绳长:304.0 井深:3605,甲家绳长:1325,乙家绳长:955.0,丙家绳长:740.0,丁家绳长:645.0,戊家绳长:380.0 井深:4326,甲家绳长:1590,乙家绳长:1146.0,丙家绳长:888.0,丁家绳长:774.0,戊家绳长:456.0 井深:5047,甲家绳长:1855,乙家绳长:1337.0,丙家绳长:1036.0,丁家绳长:903.0,戊家绳长:532.0 井深:5768,甲家绳长:2120,乙家绳长:1528.0,丙家绳长:1184.0,丁家绳长:1032.0,戊家绳长:608.0 井深:6489,甲家绳长:2385,乙家绳长:1719.0,丙家绳长:1332.0,丁家绳长:1161.0,戊家绳长:684.0 井深:7210,甲家绳长:2650,乙家绳长:1910.0,丙家绳长:1480.0,丁家绳长:1290.0,戊家绳长:760.0 井深:7931,甲家绳长:2915,乙家绳长:2101.0,丙家绳长:1628.0,丁家绳长:1419.0,戊家绳长:836.0 井深:8652,甲家绳长:3180,乙家绳长:2292.0,丙家绳长:1776.0,丁家绳长:1548.0,戊家绳长:912.0 井深:9373,甲家绳长:3445,乙家绳长:2483.0,丙家绳长:1924.0,丁家绳长:1677.0,戊家绳长:988.0
方法二:如果戊家的绳子是最短的,所以以e为循环单位,第二组解算出来的就很大了
for k in range(1,10): for e in range(1,10000): a = 721*k-6*e b = 721*k-2*a c = 721*k-3*b d = 721*k-4*c e = 721*k-5*d result1 = a+6*e result2 = b+2*a result3 = c+3*b result4 = d+4*c result5 = e+5*d if result1==result2==result3==result4==result5: print("井深:{},甲家绳长:{},乙家绳长:{},丙家绳长:{},丁家绳长:{},戊家绳长:{}".format(result1,a,b,c,d,e))
执行结果:
井深:721,甲家绳长:265,乙家绳长:191,丙家绳长:148,丁家绳长:129,戊家绳长:76 井深:1442,甲家绳长:530,乙家绳长:382,丙家绳长:296,丁家绳长:258,戊家绳长:152 井深:2163,甲家绳长:795,乙家绳长:573,丙家绳长:444,丁家绳长:387,戊家绳长:228 井深:2884,甲家绳长:1060,乙家绳长:764,丙家绳长:592,丁家绳长:516,戊家绳长:304 井深:3605,甲家绳长:1325,乙家绳长:955,丙家绳长:740,丁家绳长:645,戊家绳长:380 井深:4326,甲家绳长:1590,乙家绳长:1146,丙家绳长:888,丁家绳长:774,戊家绳长:456 井深:5047,甲家绳长:1855,乙家绳长:1337,丙家绳长:1036,丁家绳长:903,戊家绳长:532 井深:5768,甲家绳长:2120,乙家绳长:1528,丙家绳长:1184,丁家绳长:1032,戊家绳长:608 井深:6489,甲家绳长:2385,乙家绳长:1719,丙家绳长:1332,丁家绳长:1161,戊家绳长:684