Как уменьшить диапазон цикла for в Python?Python

Программы на Python
Anonymous
Как уменьшить диапазон цикла for в Python?

Сообщение Anonymous »

В этом вопросе я хотел найти min(m+k) такой, что mCk =n, я написал код для перебора моей последовательности. Проблема заключалась в том, что мой код недостаточно быстр, поэтому я хочу уменьшить длина цикла for по мере k прогресса

Код: Выделить всё

import math
print("the input is the maximum number $n$ to check for i.e for all u between 1, n the code gives the min m+k suck that mCk =n , the output is in the for of $(n , min (m+k : mCk=n)) $")
u=int(input())
for n in range (2,u+1):
C=[]
stop=1
l=0
for m in range (1, n+1):
s=0
if stop==-1:
break
for k in range(1, math.floor(m/2)+1-l):
if math.comb(m,k)>n:
l=l+1
break
if math.comb(m,k)==n:
C.insert(s,m+k )
s=s+1
if min(C)

Подробнее здесь: [url]https://stackoverflow.com/questions/78749420/how-to-decrease-the-range-of-the-for-loop-in-python[/url]

Вернуться в «Python»