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