#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, k;
  cin >> n >> k;
  vector<int> a(n);
  vector<long long> s(n + 1);
  for (int i = 0; i < n; i++) cin >> a[i];
  s[0] = 0;
  for (int i = 0; i < n; i++) s[i + 1] = s[i] + a[i];
  map<long long, int> f;
  f[0]++;
  long long ans = 0;
  long long mins = 0;
  long long maxs = 0;
  for (int i = 0; i < n; i++) {
    if (k == 1) {
      ans += f[s[i + 1] - 1];
      f[s[i + 1]]++;
      continue;
    } else if (k == -1) {
      ans += f[s[i + 1] - 1];
      ans += f[s[i + 1] + 1];
      f[s[i + 1]]++;
      continue;
    }
    for (long long p = 1;
         abs(p) <= max(abs(s[i + 1] - mins), abs(s[i + 1] - maxs)); p *= k) {
      ans += f[s[i + 1] - p];
    }
    mins = min(mins, s[i + 1]);
    maxs = max(maxs, s[i + 1]);
    f[s[i + 1]]++;
  }
  cout << ans << "\n";
  return 0;
}
