Advertisement
Guest User

Untitled

a guest
May 23rd, 2017
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.50 KB | None | 0 0
  1. def Gcd(a, b):
  2.   if b == 0:
  3.     return a
  4.   return Gcd(b, a % b)
  5.  
  6. def Solve(L):
  7.   y = L[0]
  8.   L1 = [abs(x - y) for x in L]
  9.   g = reduce(Gcd, L1)
  10.   if y % g == 0:
  11.     return 0
  12.   else:
  13.     return g - (y % g)
  14.  
  15. with open('B-large-practice.in') as f:
  16.   lines = f.readlines()
  17.  
  18. with open('B-large-practice.out', 'w') as output:
  19.   N = int(lines[0])
  20.   for testcase, i in enumerate(range(N)):
  21.     codes = map(int,lines[i+1].split())
  22.     output.write("Case #%d: %d\n" % (testcase+1, Solve(codes[1:])))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement