fork download
  1. # ------------------- 可修改数字 -------------------
  2. dividend = 106692
  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.04s 9368KB
stdin
Standard input is empty
stdout
106692 ÷ 680 = 156.9
---
590、595
590*93.5=55165
595*86.6=51527
---
595、600
595*93.6=55692
600*85.0=51000
---
600、590
600*90.5=54300
590*88.8=52392
---
605、590
605*91.8=55539
590*86.7=51153
---
610、590
610*89.5=54595
590*88.3=52097
---
615、590
615*83.4=51291
590*93.9=55401
---
620、590
620*87.2=54064
590*89.2=52628
---
625、590
625*91.6=57250
590*83.8=49442
---
630、590
630*89.0=56070
590*85.8=50622
---