Advertisement
Guest User

frobenius

a guest
Jul 7th, 2020
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.68 KB | None | 0 0
  1. from functools import reduce
  2. from math import gcd
  3.  
  4. A = [10, 18, 26, 33, 35]
  5.  
  6. S = [0, 35, 35, 35, 35, 35, 35, 35, 35, 35]
  7. P = [4, None, None, None, None, None, None, None, None, None]
  8. Q = [[0]]
  9. L = [1, 0, 0, 0, 0]
  10. Z = [0]
  11. Amod = [A[i] % A[0] for i in range(len(A))]
  12. Aquot = [A[i] // A[0] for i in range(len(A))]
  13.  
  14. while Z:
  15.     w = Z.pop(0)
  16.  
  17.     while Q[w]:
  18.         v = Q[w].pop()
  19.  
  20.         for j in range(2, P[v]+1):
  21.             u = v + Amod[j-1]
  22.             w = S[v] + Aquot[j-1]
  23.  
  24.             if u >= A[0]:
  25.                 u = u - A[0]
  26.                 w = w - 1
  27.  
  28.             if w < S[u]:
  29.                 Q[w].append(u)
  30.                 S[u] = w
  31.                 P[u] = j
  32.  
  33.                 if L[w] == 0:
  34.                     Z.append(w)
  35.                     Z.sort()
  36.  
  37. for v in range(len(S)):
  38.     print(S[v] * A[0] + v - A[0])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement