尤拉計劃705:除數序列的逆轉次數

lt發表於2020-03-08

pe705en

測試程式碼

def sort_count(li):
 le=len(li)
 c=0
 while True:
  c1=c
  for i in range(le-1):
   if li[i]>li[i+1]:
    li[i],li[i+1]=li[i+1],li[i]
    #print(li)
    c+=1
    break
  if c1==c:break  
 return c

def divide_seq(li):
 le=len(li)
 d=[]
 for i in range(le):
  d.append([])
  for j in range(1,li[i]+1):
   if li[i] % j ==0:
    d[i].append(j)
 return d

l20=[2,3,5,7,1,1,1,3,1,7,1,9]
def F():
 s=0
 for i in itertools.product(*divide_seq(l20)):s+=sort_count(list(i))
 print (s)


>>> F()
3312

相關文章