1 से 20 तक के सभी संख्याओं से विभाज्य सबसे छोटी धनात्मक संख्या खोजने के लिए अधिक कुशल brute-force algorithm
📁 पायथन
एक समस्या है:
2520 सबसे छोटी संख्या है जिसे 1 से 10 तक की प्रत्येक संख्या से बिना शेषफल के विभाजित किया जा सकता है।
वह सबसे छोटी धनात्मक संख्या ज्ञात करें जो 1 से 20 तक की सभी संख्याओं से विभाज्य हो?
मैंने इस समस्या को एक खराब optimized brute-force algorithm लिखकर हल किया।
calculate = Truemax_number = 20min_number = 1current_divisible = 2520count = 0while calculate: for i in range(2, max_number + 1): if current_divisible % i == 0: count += 1 min_number = current_divisible else: count = 0