## 思路

$\frac{p}{s}=k\to p=s\cdot k$$\frac{p}{s} = k \rightarrow p = s \cdot k$, 因为 $p=s\cdot k\le 2\cdot {10}^{5}\cdot {10}^{18}\cdot {10}^{5}=2\cdot {10}^{18}$$p = s \cdot k \leq 2 \cdot 10^5 \cdot 10^{18} \cdot 10^5 = 2 \cdot 10^{18}$ ，所以区间中大于1的元素个数应该要小于60（ ${2}^{61}\approx 2.3\cdot {10}^{18}$$2^{61} \approx 2.3 \cdot 10^{18}$), 对于所有l，循环r，当区间p大于 ${2}^{18}$$2^{18}$时，退出循环，l++

## 代码

GNU C++17 Accepted 499 ms 1580 KB

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 2e5 + 100;
const ll MAX = 2E18 + 100;
int n, k, a[maxn];
int pos[maxn], cnt;

int main()
{
cin >> n >> k;
for (int i = 0; i < n; ++i)
{
cin >> a[i];
if (a[i] > 1) pos[cnt++] = i;
}
pos[cnt++] = n;
ll s, p, ans = 0;
for (int l = 0; l < n; ++l)
{
s = p = a[l];
for (int r = l; r < n; )
{
int nxt = pos[upper_bound(pos, pos + cnt, r) - pos];
if (p >= s * k && p % k == 0)
{
ll need1 = p / k - s;
if (nxt - r - 1 >= need1) ++ans;
}
if(nxt == n) break;
s += a[nxt] + nxt - r - 1;
if (p >= MAX / a[nxt]) break;
p *= a[nxt];
r = nxt;
}
}
cout << ans << endl;
return 0;
}