#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e5 + 10;
long long a[MAXN];
long long sum[MAXN];
map<long long, int> m;
int n, k;
long long mul(int x, int y) {
  long long tmp = 1;
  for (int i = 1; i <= y; i++) {
    tmp *= x;
  }
  return tmp;
}
long long solve() {
  memset(sum, 0, sizeof(sum));
  sum[0] = 0;
  long long cnt = 0;
  long long tmp = k;
  long long num;
  if (tmp < 0) tmp = -tmp;
  for (int i = 0; i <= n; i++) {
    if (i > 0) sum[i] = sum[i - 1] + a[i];
    cnt += m[sum[i]];
    if (k == 1)
      m[1 + sum[i]]++;
    else if (k == -1)
      m[1 + sum[i]]++, m[-1 + sum[i]]++;
    else
      for (int j = 0; j <= 60; j++) {
        num = mul(k, j);
        if (num > 1e15 || num < -1e15) break;
        m[num + sum[i]]++;
      }
  }
  return cnt;
}
int main() {
  while (scanf("%d %d", &n, &k) != EOF) {
    m.clear();
    for (int i = 1; i <= n; i++) scanf("%I64d", &a[i]);
    printf("%I64d\n", solve());
  }
  return 0;
}
