#include <bits/stdc++.h>
using namespace std;
map<long long, long long> M;
void syn() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
}
int main() {
  long long n, k, MAX = 0, s, c = 0, i, w;
  syn();
  cin >> n >> k;
  vector<long long> A(n);
  for (i = 0; i < n; i++) {
    cin >> A[i];
    MAX += abs(A[i]);
  }
  if (k == 1) {
    s = 0;
    w = 1;
    M[0] = 1;
    for (i = 0; i < n; i++) {
      s += A[i];
      long long x = s - w;
      c += M[x];
      M[s]++;
    }
  } else if (k == -1) {
    s = 0;
    w = 1;
    M[0] = 1;
    for (i = 0; i < n; i++) {
      s += A[i];
      long long x = s - w;
      if (M.find(x) != M.end()) c += M[x];
      x = s + w;
      if (M.find(x) != M.end()) c += M[x];
      M[s]++;
    }
  } else {
    s = 0;
    M[0] = 1;
    for (i = 0; i < n; i++) {
      s += A[i];
      for (w = 1; abs(w) <= MAX; w *= k) {
        long long x = s - w;
        if (M.find(x) != M.end()) c += M[x];
      }
      M[s]++;
    }
  }
  cout << c << endl;
}
