23dfcca431 2011-02-23 kinaba: ' 23dfcca431 2011-02-23 kinaba: ' Written in VBScript 23dfcca431 2011-02-23 kinaba: ' 23dfcca431 2011-02-23 kinaba: 23dfcca431 2011-02-23 kinaba: Function ReadLine() 23dfcca431 2011-02-23 kinaba: Dim s 23dfcca431 2011-02-23 kinaba: s = Split(WScript.StdIn.ReadLine, " ") 23dfcca431 2011-02-23 kinaba: For i = LBound(s) To UBound(s) 23dfcca431 2011-02-23 kinaba: s(i) = CLng(s(i)) 23dfcca431 2011-02-23 kinaba: Next 23dfcca431 2011-02-23 kinaba: ReadLine = s 23dfcca431 2011-02-23 kinaba: End Function 23dfcca431 2011-02-23 kinaba: 23dfcca431 2011-02-23 kinaba: Function Gcd(a, b) 23dfcca431 2011-02-23 kinaba: If a = 0 Then 23dfcca431 2011-02-23 kinaba: Gcd = b 23dfcca431 2011-02-23 kinaba: Else 23dfcca431 2011-02-23 kinaba: Gcd = Gcd(b mod a, a) 23dfcca431 2011-02-23 kinaba: End If 23dfcca431 2011-02-23 kinaba: End Function 23dfcca431 2011-02-23 kinaba: 23dfcca431 2011-02-23 kinaba: Function Solve(T) 23dfcca431 2011-02-23 kinaba: Dim g, r 23dfcca431 2011-02-23 kinaba: g = Abs(T(1) - T(2)) 23dfcca431 2011-02-23 kinaba: For i = 2 To UBound(T) 23dfcca431 2011-02-23 kinaba: g = Gcd(g, Abs(T(1) - T(i))) 23dfcca431 2011-02-23 kinaba: Next 23dfcca431 2011-02-23 kinaba: r = T(1) mod g 23dfcca431 2011-02-23 kinaba: If r = 0 Then 23dfcca431 2011-02-23 kinaba: Solve = 0 23dfcca431 2011-02-23 kinaba: Else 23dfcca431 2011-02-23 kinaba: Solve = g - r 23dfcca431 2011-02-23 kinaba: End If 23dfcca431 2011-02-23 kinaba: End Function 23dfcca431 2011-02-23 kinaba: 23dfcca431 2011-02-23 kinaba: C = ReadLine()(0) 23dfcca431 2011-02-23 kinaba: For CaseID = 1 To C 23dfcca431 2011-02-23 kinaba: WScript.StdOut.WriteLine "Case #" & CaseID & ": " & Solve(ReadLine) 23dfcca431 2011-02-23 kinaba: Next