fork download
  1. # ------------------- 可修改数字 -------------------
  2. dividend = 190580
  3. start =620
  4. end = 750
  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 9516KB
stdin
Standard input is empty
stdout
190580 ÷ 650 = 293.2
---
620、625
620*159.0=98580
625*147.2=92000
---
625、630
625*150.2=93875
630*153.5=96705
---
630、620
630*154.2=97146
620*150.7=93434
---
635、620
635*152.4=96774
620*151.3=93806
---
640、620
640*151.5=96960
620*151.0=93620
---
645、620
645*146.0=94170
620*155.5=96410
---
655、620
655*146.8=96154
620*152.3=94426
---
660、620
660*148.6=98076
620*149.2=92504
---
665、620
665*150.0=99750
620*146.5=90830
---