summaryrefslogtreecommitdiff
path: root/2010/qual/b/b.py
diff options
context:
space:
mode:
Diffstat (limited to '2010/qual/b/b.py')
-rw-r--r--2010/qual/b/b.py21
1 files changed, 21 insertions, 0 deletions
diff --git a/2010/qual/b/b.py b/2010/qual/b/b.py
new file mode 100644
index 0000000..82bc96e
--- /dev/null
+++ b/2010/qual/b/b.py
@@ -0,0 +1,21 @@
+f = open('2.in', 'r')
+o = open('2.out', 'w')
+
+c = int(f.readline().strip())
+
+def gcd(a, b):
+ return a if b==0 else gcd(b, a % b)
+
+for i in range(c):
+ t = map(int, f.readline().strip().split(' ')[1:])
+ l = [abs(x - t[0]) for x in t]
+ g = reduce(gcd, l)
+
+ if t[0] % g == 0:
+ r = 0
+ else:
+ r = g - (t[0] % g)
+
+ s = "Case #%d: %s\n" % (i+1, r)
+
+ o.write(s)