static void Main(string[] args) { using (var prob = new CodeJamProblem('c', ProblemType.Large, 0)) { int tcase = prob.ReadLineInt32(); for (int cases = 0; cases < tcase; cases++) { long[] a = prob.ReadInt64Array(); int n = (int)a[0]; l = a[1]; h = a[2]; List <long> x = new List <long>(); long[] ff = prob.ReadInt64Array(); for (int i = 0; i < n; i++) { x.Add(ff[i]); } long[] f = x.Distinct().ToArray(); Array.Sort(f); n = f.Length; long[] gcd = new long[n]; long[] lcd = new long[n]; int start = 0; while (f[start] == 0 && start < n) { start++; } lcd[start] = f[start]; for (int i = start + 1; i < n; i++) { if (lcd[i - 1] == -1) { lcd[i] = -1; } else { lcd[i] = clcd(lcd[i - 1], f[i]); } } gcd[n - 1] = f[n - 1]; for (int i = n - 2; i >= start; i--) { gcd[i] = cgcd(f[i], gcd[i + 1]); } long ans = getMin(l, h, gcd[0]); for (int i = start; i < n - 1; i++) { if (i < n - 2 && f[i] == f[i + 1]) { continue; } if (lcd[i] == -1) { break; } if (gcd[i + 1] % lcd[i] != 0) { continue; } if (lcd[i] <= gcd[i + 1]) { long tl = (l + lcd[i] - 1) / lcd[i]; long th = h / lcd[i]; long tans = getMin(tl, th, gcd[i + 1] / lcd[i]) * lcd[i]; if (tans >= 0 && (ans == -1 || ans > tans)) { ans = tans; } } } if (lcd[n - 1] != -1) { long ttans = (l + lcd[n - 1] - 1) / lcd[n - 1] * lcd[n - 1]; if (ttans <= h && (ans == -1 || ttans < ans)) { ans = ttans; } } if (ans == -1) { prob.OutputCase("NO"); } else { prob.OutputCase(ans.ToString()); } } } }
static void Main(string[] args) { using (var prob = new CodeJamProblem('b', ProblemType.Large, 0)) { int tcase = prob.ReadLineInt32(); for (int cases = 0; cases < tcase; cases++) { long[] a = prob.ReadInt64Array(); long l = a[0]; long t = a[1]; long n = a[2]; long c = a[3]; long sum = 0; for (int i = 0; i < c; i++) { a[i] = a[i + 4] * 2; sum += a[i]; } long left = t; int now = 0; long ans = 0; while (now < n && left >= a[now % c]) { left -= a[now % c]; ans += a[now % c]; now++; } if (now == n) { prob.OutputCase(ans.ToString()); continue; } long[] ap = new long[11000 * 2]; ans += left; ap[a[now % c] - left]++; long numleft = n - now - 1; for (int i = 0; i < c; i++) { if (i < (numleft % c)) { ap[a[(now + 1 + i) % c]] += numleft / c + 1; } else { ap[a[(now + 1 + i) % c]] += numleft / c; } } for (int i = 21000; i >= 0; i--) { if (ap[i] <= l) { l -= ap[i]; ans += ap[i] * i / 2; } else { ans += ap[i] * i - (l * i / 2); l = 0; } } prob.OutputCase(ans.ToString()); } } }