#include <bits/stdc++.h>
using namespace std;
inline void scale(int x) {
  cout.precision(x);
  cout << fixed;
}
long long lpow(long long x, int y) {
  if (!y) return 1;
  long long t = lpow(x, y / 2);
  if (y & 1) return (y > 0) ? x * t * t : (t * t) / x;
  return t * t;
}
int ipow(int x, int y) {
  if (!y) return 1;
  int t = ipow(x, y / 2);
  if (y & 1) return (y > 0) ? x * t * t : (t * t) / x;
  return t * t;
}
void toBin(int a, int len) {
  vector<int> v;
  while (a) {
    v.emplace_back(a & 1), a >>= 1;
  }
  while ((int)v.size() < len) v.emplace_back(0);
  reverse(v.begin(), v.end());
  for (auto p : v) cout << p;
  cout << endl;
}
void split(vector<string> &tmp, string &line) {
  stringstream ss(line);
  string s;
  tmp.clear();
  while (ss >> s) tmp.emplace_back(s);
}
inline void fastio(int debug) {
  if (debug) {
    cout << "DEBUGGING MODE..." << endl;
    freopen("in", "r", stdin);
  } else {
    ios_base::sync_with_stdio(false), cin.tie(0);
    cout.tie(0);
  }
}
bool DRAFT = 1;
int a[100005], n, k, ec;
long long ans, pw[55], pref;
map<long long, long long> M;
int main(void) {
  fastio(0);
  cin >> n >> k;
  for (int i = 1; i < n + 1; i++) cin >> a[i];
  if (k != 1 && k != -1) {
    long long lim = 1e14;
    for (long long i = 1; abs(i) <= lim; i *= k) {
      pw[ec++] = i;
    }
  } else {
    pw[ec++] = 1;
    if (k == -1) pw[ec++] = -1;
  }
  for (int j = 0; j < n; j++) {
    M[pref]++;
    pref += a[j + 1];
    for (int i = 0; i < ec; i++) {
      if (M.count(pref - pw[i]) > 0) ans += M[pref - pw[i]];
    }
  }
  cout << ans << "\n";
  return 0;
}
