1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
| #include <iostream> using namespace std; typedef long long LL; const int N = 40001; int n, m, k; int a[N], b[N]; int s1[N], s2[N]; void work(int w[], int s[], int n) { for (int i = 0, j = 0; i < n; ++i) if (w[i]) { ++j; ++s[1], --s[j + 1]; } else { j = 0; } for (int i = 1; i <= n; ++i) s[i] += s[i - 1]; } int main() { cin >> n >> m >> k; for (int i = 0; i < n; ++i) cin >> a[i]; for (int i = 0; i < m; ++i) cin >> b[i]; work(a, s1, n); work(b, s2, m); LL ans = 0; for (int i = n; i >= 1; --i) { if (k % i) continue; int j = k / i; if (j > m) break; ans += s1[i] * s2[j]; } cout << ans << endl; return 0; }
|