#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int n, k, mx = 1e15;
  cin >> n >> k;
  long long int a[n];
  for (long long int i = 0; i < n; i++) cin >> a[i];
  map<long long int, long long int> make_pair;
  long long int ansr = 0;
  make_pair[0] = 1;
  for (long long int i = 0; i < n; i++) {
    if (i) a[i] += a[i - 1];
    if (k == 1)
      ansr += make_pair[a[i] - 1];
    else if (k == -1) {
      ansr += make_pair[a[i] - 1];
      ansr += make_pair[a[i] + 1];
    } else {
      long long int m = 1;
      while (m < mx) {
        ansr += make_pair[a[i] - m];
        m *= k;
      }
    }
    make_pair[a[i]]++;
  }
  cout << ansr;
}
