Any faster way to find the number of “lucky triples”?

前端 未结 4 1219
盖世英雄少女心
盖世英雄少女心 2021-01-03 10:28

I am working on a code challenge problem -- \"find lucky triples\". \"Lucky triple\" is defined as \"In a list lst, for any combination of triple like (ls

4条回答
  •  长发绾君心
    2021-01-03 11:22

    Full working solution in python:

    c = [0] * len(l)
    print c
    count = 0
    
    for i in range(0,len(l)):
      j=0
      for j in range(0, i):
        if l[i] % l[j] == 0:
          c[i] = c[i] + 1
          count = count + c[j]
        print j           
    
    print c
    print count
    

提交回复
热议问题