#include <bits/stdc++.h>
using namespace std;
const int maxn = 200000 + 10;
const long long INF = 1e15 + 7;
const int MOD = 1e9 + 7;
const double eps = 1e-10;
const double pi = acos(-1);
int T, cases, n, m;
map<long long, int> Map;
vector<int> G[maxn];
long long a[maxn], sum[maxn], ans;
void f(long long cnt, int i) {
  if (Map.count(cnt)) {
    int x = Map[cnt];
    int y = G[x].size();
    int tmp = lower_bound(G[x].begin(), G[x].end(), i) - G[x].begin();
    ans += y - tmp;
  }
}
int main() {
  ios::sync_with_stdio(false);
  ;
  long long n, k, tot = 0;
  cin >> n >> k;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    sum[i] = sum[i - 1] + a[i];
    long long tmp = sum[i];
    if (!Map.count(tmp)) Map[tmp] = ++tot;
    G[Map[tmp]].push_back(i);
  }
  for (int i = 1; i <= n; i++) {
    if (k == 1 || k == -1) {
      long long cnt = sum[i - 1] + 1;
      f(cnt, i);
      if (k == -1) {
        cnt = sum[i - 1] - 1;
        f(cnt, i);
      }
    } else {
      long long cnt = 1;
      while (abs(cnt) <= INF) {
        f(cnt + sum[i - 1], i);
        cnt *= k;
      }
    }
  }
  cout << ans << endl;
  return 0;
}
