vector<int> primes; bool isprime[N]; voidpreProcess() { fill(isprime + 2, isprime + N, true); for (int x = 2; x < N; x++) { if (isprime[x]) primes.push_back(x); for (int y : primes) { if (x * y >= N) break; isprime[x * y] = 0; if (x % y == 0) break; } } } voidwork() { cin >> n >> m; int ans = 1; for (int i = 1; i * i <= n; i++) { if (n % i == 0) { if (n / i >= m) ans = max(ans, i); if (i >= m) ans = max(ans, n / i); } } cout << ans << endl; } intmain() { preProcess(); ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); int t; cin >> t; while (t --> 0) { work(); } }
int n, m, k, q; string s; ll a[27][27]; int tr[N * 8][27]; ll cnt[N]; int tot = 1; voidinsert(string s) { int now = 1; s = s + (char)('a' - 1); for (char nowchar : s) { int x = nowchar - 'a' + 1; for (int y = 0; y < 27; y++) if (x != y && tr[now][y]) a[y][x] += cnt[tr[now][y]]; if (!tr[now][x]) tr[now][x] = ++tot; now = tr[now][x]; cnt[now]++; } } voidwork() { cin >> n >> q; for (int i = 1; i <= n; i++) { cin >> s; insert(s); } while (q--) { string cmp; cin >> cmp; ll ans = 0; cmp = (char)('a' - 1) + cmp; for (int i = 0; i < 27; i++) for (int j = i + 1; j < 27; j++) ans = (ans + a[cmp[j] - 'a' + 1][cmp[i] - 'a' + 1]); cout << ans << endl; } } intmain() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); work(); }