Artifact Content
Not logged in

Artifact 4dbab301b915fb0de86c09d812f2d0516844f33a


'
' Written in VBScript
'

Function ReadLine()
	Dim s
	s = Split(WScript.StdIn.ReadLine, " ")
	For i = LBound(s) To UBound(s)
		s(i) = CLng(s(i))
	Next
	ReadLine = s
End Function

Function Gcd(a, b)
	If a = 0 Then
		Gcd = b
	Else
		Gcd = Gcd(b mod a, a)
	End If
End Function

Function Solve(T)
	Dim g, r
	g = Abs(T(1) - T(2))
	For i = 2 To UBound(T)
		g = Gcd(g, Abs(T(1) - T(i)))
	Next
	r = T(1) mod g
	If r = 0 Then
		Solve = 0
	Else
		Solve = g - r
	End If
End Function

C = ReadLine()(0)
For CaseID = 1 To C
	WScript.StdOut.WriteLine "Case #" & CaseID & ": " & Solve(ReadLine)
Next