#include <bits/stdc++.h>
using namespace std;
const int dx[9] = {0, 1, -1, 0, 0, -1, -1, 1, 1};
const int dy[9] = {0, 0, 0, -1, 1, -1, 1, -1, 1};
const double pi = acos(-1.0);
const int N = 1e5 + 100;
long long pre[N], a[N], temp[200], ans = 0;
int n, k, ma = 0;
map<long long, long long> dic;
int main() {
  scanf("%d", &n), scanf("%d", &k);
  long long t = 1;
  temp[0] = 1;
  if (k == 1 || k == -1) {
    if (k == 1) {
      ma = 0;
      temp[0] = 1;
    } else {
      ma = 1;
      temp[0] = 1;
      temp[1] = -1;
    }
  } else {
    while (abs(t * k) < 1e15) {
      ma++;
      t = t * k;
      temp[ma] = t;
    }
  }
  for (int i = 1; i <= n; i++) scanf("%lld", &a[i]);
  for (int i = 0; i <= ma; i++) dic[temp[i] + 0]++;
  for (int i = 1; i <= n; i++) {
    pre[i] = pre[i - 1] + a[i];
    ans += dic[pre[i]];
    for (int j = 0; j <= ma; j++) dic[pre[i] + temp[j]]++;
  }
  printf("%lld\n", ans);
  return 0;
}
