#include <bits/stdc++.h>
using namespace std;
template <typename T>
ostream& operator<<(ostream& out, const vector<T>& v) {
  out << "[";
  for (auto vi : v) out << vi << ", ";
  out << "]";
  return out;
}
int DX[] = {0, +1, 0, -1, 0};
int DY[] = {+1, 0, -1, 0, 0};
int readInt() {
  int temp;
  scanf("%d", &temp);
  return temp;
}
vector<int> a;
map<long long, int> m;
int n, k;
void solve() {
  scanf("%d%d", &n, &k);
  for (int i = 0; i < (n); ++i) {
    int temp;
    scanf("%d", &temp);
    a.push_back(temp);
  }
  set<long long> kk;
  for (long long p = 1; - 1e15 < p && p < 1e15; p *= k) {
    if (kk.count(p) == 0)
      kk.insert(p);
    else
      break;
  }
  long long sum = 0;
  long long result = 0;
  for (int i = 0; i < n; i++) {
    m[sum]++;
    sum += a[i];
    for (auto p : kk) {
      if (m.find(sum - p) != m.end()) {
        result += m[sum - p];
      }
    }
  }
  cout << result;
}
void readData() {}
int main() {
  ios::sync_with_stdio(false);
  readData();
  solve();
  return 0;
}
