#include <bits/stdc++.h>
using namespace std;
int n, k, a[100005];
long long lf[100005];
long long countSegs(long long pk) {
  long long res = 0;
  map<long long, int> cnt;
  for (int i = 0; i <= n; i++) {
    cnt[lf[i]]++;
  }
  for (int i = 0; i < n; i++) {
    cnt[lf[i]]--;
    res += cnt[pk + lf[i]];
  }
  return res;
}
long long solve() {
  lf[0] = 0;
  for (int i = 1; i <= n; i++) {
    lf[i] = lf[i - 1] + a[i];
  }
  long long res = 0;
  long long pk = 1;
  while (abs(pk) <= 1000000000000000) {
    res += countSegs(pk);
    pk *= k;
    if (pk == 1) {
      break;
    }
  }
  return res;
}
int main() {
  ios::sync_with_stdio(false);
  cin >> n >> k;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
  }
  cout << solve() << endl;
  return 0;
}
