#include <bits/stdc++.h>
using namespace std;
vector<long long> check(long long n) {
  long long k = 200000000000000;
  vector<long long> ret;
  if (n == 1)
    return vector<long long>{1};
  else if (n == -1) {
    ret.push_back(-1);
    return vector<long long>{1, -1};
  } else {
    long long cur = 1;
    while (abs(cur) < k) {
      ret.push_back(cur);
      cur *= n;
    }
  }
  return ret;
}
int main() {
  ios_base::sync_with_stdio(false);
  long long n, k;
  cin >> n >> k;
  vector<long long> vec(n);
  for (int i = 0; i < n; ++i) cin >> vec[i];
  vector<long long> ch = check(k);
  map<long long, long long> m;
  m[0] = 1;
  long long sum = 0, ans = 0, s = ch.size();
  for (int i = 0; i < n; ++i) {
    sum += vec[i];
    for (int j = 0; j < s; ++j) {
      long long f = sum - ch[j];
      if (m[f]) ans += m[f];
    }
    ++m[sum];
  }
  cout << ans << "\n";
  return 0;
}
