#include <bits/stdc++.h>
void init() { freopen("a.in", "r", stdin); }
using namespace std;
long long a[300000];
void solve() {
  long long n, k;
  map<long long, long long> z;
  long long ans = 0;
  cin >> n >> k;
  vector<long long> st;
  st.push_back(1);
  if (k == -1) st.push_back(-1);
  if (k != 1 && k != -1) {
    st.push_back(k);
    long long kk = k;
    while (kk <= 1e14 + 41) {
      kk *= k;
      st.push_back(kk);
    }
  }
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  long long s = 0;
  for (int i = 0; i < n; i++) {
    s += a[i];
    for (int j = 0; j < (int)st.size(); j++) {
      if (s == st[j]) ans++;
      long long diff = s - st[j];
      ans += z[diff];
    }
    z[s]++;
  }
  cout << ans;
}
int main() {
  solve();
  return 0;
}
