#define N 5050 usingnamespacestd; typedeflonglong ll;
template <class > inlinevoidread(& x) { x = 0; char ch = getchar(); int f = 1; for (; !isdigit(ch); ch = getchar()) if (ch == '-') f = -1; for (; isdigit(ch); x = x * 10 + ch - '0', ch = getchar()); x *= f; }
int T, n, s, V[55], C[55]; ll ret, f[N];
inlinevoid _01(int p) { memset(f, 0, sizeof(f)); f[0] = 1; for (int i = 1; i <= n; ++i) { if (C[i] < p) continue; for (int j = s / p; j >= V[i]; --j) f[j] += f[j - V[i]]; } ret += f[s / p]; }
intmain(){ read(T); for (int kase = 1; kase <= T; ++kase) { read(s), read(n); ret = 0; for (int i = 1; i <= n; ++i) read(V[i]), read(C[i]); for (int i = 1; i * i <= s; ++i) { if (s % i) continue; if (s == i * i) _01(i); else _01(s / i), _01(i); } printf("Case %d: %lldn", kase, ret); } return0; }
近期评论