#include <bits/stdc++.h>
using namespace std;
const int MaxN = 1e5 + 5;
const long long INF = 1e14 + 5;
int n, k;
long long ans;
int box[MaxN];
map<long long, int> cont;
map<long long, bool> vis;
int main() {
  while (~scanf("%d %d", &n, &k)) {
    for (int i = 1; i <= n; i++) scanf("%d", &box[i]);
    for (long long i = 1; !vis[i] && abs(i) <= INF; i *= k) {
      vis[i] = 1;
      cont.clear();
      cont[0] = 1;
      long long sum = 0;
      for (int j = 1; j <= n; j++) {
        sum += box[j];
        ans += cont[sum - i];
        cont[sum]++;
      }
    }
    printf("%I64d\n", ans);
    vis.clear();
    cont.clear();
    ans = 0;
    memset(box, 0, sizeof(box));
  }
  return 0;
}
