fork download
  1. # ------------------- 可修改数字 -------------------
  2. dividend = 52880
  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 9484KB
stdin
Standard input is empty
stdout
590、595
590*38.8=22892
595*50.4=29988
---
595、600
595*44.0=26180
600*44.5=26700
---
600、590
600*42.9=25740
590*46.0=27140
---
605、590
605*40.4=24442
590*48.2=28438
---
610、590
610*42.1=25681
590*46.1=27199
---
615、590
615*38.4=23616
590*49.6=29264
---
620、590
620*43.8=27156
590*43.6=25724
---
625、590
625*42.6=26625
590*44.5=26255
---
630、590
630*41.7=26271
590*45.1=26609
---
635、590
635*41.0=26035
590*45.5=26845
---