#include <bits/stdc++.h>
using namespace std;
const int MAXN = 112345;
const long long MAXP = 1.e15;
int n;
long long k;
long long a[MAXN];
long long p[MAXN];
int np;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> k;
  for (int i = 0; i < n; i++) cin >> a[i];
  p[0] = 1ll;
  if (k == 1ll) {
    np = 1;
  } else if (k == -1ll) {
    p[1] = -1ll;
    np = 2;
  } else {
    do {
      np++;
      p[np] = p[np - 1] * k;
    } while (llabs(p[np]) <= MAXP);
  }
  map<long long, long long> count;
  long long sum = 0;
  count[sum]++;
  long long ans = 0;
  for (int i = 0; i < n; i++) {
    sum += a[i];
    count[sum]++;
    for (int j = 0; j < np; j++) {
      auto it = count.find(sum - p[j]);
      if (it != count.end()) ans += it->second;
    }
  }
  cout << ans << endl;
}
