#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e5 + 5;
int a[MAXN];
long long suma[MAXN];
int n, k;
map<long long, int> mapa;
int main() {
  scanf("%d %d", &n, &k);
  for (int i = (int)0; i < (int)n; i++) scanf("%d", &a[i]);
  suma[0] = a[0];
  mapa[a[0]]++;
  for (int i = (int)1; i < (int)n; i++) {
    suma[i] = a[i] + suma[i - 1];
    mapa[suma[i]]++;
  }
  long long ans = 0;
  int auxk = k;
  for (int j = (int)0; j < (int)n; j++) {
    long long pot = 1;
    while (1) {
      if (pot > 1e15 || -pot > 1e15) break;
      long long ant = 0;
      if (j) ant = suma[j - 1];
      long long t = pot + ant;
      ans += mapa[t];
      pot *= k;
      if (k == 1) break;
      if (k == -1) k = 1;
    }
    mapa[suma[j]]--;
    k = auxk;
  }
  printf("%lld\n", ans);
}
