fork download
  1. # ------------------- 可修改数字 -------------------
  2. dividend = 1790
  3. start = 590
  4. end = 680
  5. max_results = 10
  6. # ---------------------------------------------------
  7.  
  8. count = 0
  9. found = []
  10. pairs = set() # 用来防止重复组合
  11.  
  12. # 1. 优先显示整除
  13. for d in range(start, end + 1, 5):
  14. if count >= max_results:
  15. break
  16. if dividend % d == 0:
  17. print(f"{dividend} ÷ {d} = {dividend // d}")
  18. print("---")
  19. count += 1
  20. found.append(d)
  21.  
  22. # 2. 再显示一位小数
  23. for d in range(start, end + 1, 5):
  24. if count >= max_results:
  25. break
  26. if d in found:
  27. continue
  28. if (dividend * 10) % d == 0:
  29. print(f"{dividend} ÷ {d} = {dividend / d}")
  30. print("---")
  31. count += 1
  32. found.append(d)
  33.  
  34. # 3. 平衡拆分 + 去重(不会出现反过来的重复)
  35. for d in range(start, end + 1, 5):
  36. if count >= max_results:
  37. break
  38. if d in found:
  39. continue
  40.  
  41. for d2 in range(start, end + 1, 5):
  42. if d == d2:
  43. continue
  44.  
  45. # ✅ 关键:小的放前面,大的放后面,防止重复
  46. a, b = sorted((d, d2))
  47. if (a, b) in pairs:
  48. continue
  49.  
  50. best = None
  51. best_diff = 999999
  52.  
  53. max_a = int(dividend * 10 / d)
  54. for a_val in range(1, max_a):
  55. p1 = d * a_val / 10
  56. p2 = dividend - p1
  57. if p2 <= 0:
  58. continue
  59.  
  60. if (p2 * 10) % d2 == 0:
  61. val1 = a_val / 10
  62. val2 = (p2 * 10) / d2 / 10
  63. diff = abs(val1 - val2)
  64.  
  65. if diff < best_diff:
  66. best_diff = diff
  67. best = (val1, val2, int(p1), int(p2))
  68.  
  69. if best:
  70. val1, val2, p1, p2 = best
  71. print(f"{d}、{d2}")
  72. print(f"{d}*{val1}={p1}")
  73. print(f"{d2}*{val2}={p2}")
  74. print("---")
  75. pairs.add((a, b)) # 记录这组组合
  76. count += 1
  77. break
Success #stdin #stdout 0.03s 9444KB
stdin
Standard input is empty
stdout
590、600
590*1.0=590
600*2.0=1200
---
595、600
595*2.0=1190
600*1.0=600
---
600、620
600*0.4=240
620*2.5=1550
---
605、595
605*0.5=302
595*2.5=1487
---
610、590
610*1.0=610
590*2.0=1180
---
615、590
615*0.8=492
590*2.2=1298
---
620、595
620*0.2=124
595*2.8=1666
---
625、600
625*2.0=1250
600*0.9=540
---
630、590
630*0.5=315
590*2.5=1475
---
635、640
635*0.4=254
640*2.4=1536
---