#include <bits/stdc++.h>
using namespace std;
using int64 = long long;
int main() {
  int64 n, k;
  map<int64, int64> m;
  m[0] = 1;
  int64 sum = 0;
  int64 minpf = 0, maxpf = 0;
  ;
  int64 res = 0;
  cin >> n >> k;
  for (int64 i = 0; i < n; ++i) {
    int64 x;
    cin >> x;
    sum += x;
    int64 t = 1;
    if (k == 1) {
      res += m[sum - 1];
    } else if (k == -1) {
      res += m[sum - 1] + m[sum + 1];
    } else {
      while (abs(t) <= max(abs(sum - minpf), abs(sum - maxpf))) {
        res += m[sum - t];
        t *= k;
      }
    }
    m[sum] += 1;
    minpf = min(minpf, sum);
    maxpf = max(maxpf, sum);
  }
  cout << res << endl;
  return 0;
}
