fork(3) download
  1. # ------------------- 可修改数字 -------------------
  2. dividend = 190010
  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.06s 9412KB
stdin
Standard input is empty
stdout
590、595
590*161.3=95167
595*159.4=94843
---
595、600
595*158.0=94010
600*160.0=96000
---
600、590
600*162.3=97380
590*157.0=92630
---
605、590
605*155.4=94017
590*162.7=95993
---
610、590
610*160.8=98088
590*155.8=91922
---
615、590
615*154.6=95079
590*160.9=94931
---
620、590
620*154.4=95728
590*159.8=94282
---
625、590
625*161.0=100625
590*151.5=89385
---
630、590
630*157.1=98973
590*154.3=91037
---
635、590
635*158.0=100330
590*152.0=89680
---