#include <bits/stdc++.h>
using namespace std;
void solve() {
  int N, k;
  scanf("%d%d", &N, &k);
  long long x[N + 1];
  x[0] = 0;
  for (int i = 0; i < N; i++) scanf("%lld", &x[i + 1]);
  partial_sum(x, x + N + 1, x);
  if (k == 1) {
    long long ans = 0;
    map<long long, int> m;
    for (int i = N; i >= 0; i--) {
      if (m.find(x[i] + 1) != m.end()) ans += m[x[i] + 1];
      m[x[i]]++;
    }
    printf("%lld\n", ans);
  } else if (k == -1) {
    long long ans = 0;
    map<long long, int> m;
    for (int i = N; i >= 0; i--) {
      if (m.find(x[i] + 1) != m.end()) ans += m[x[i] + 1];
      if (m.find(x[i] - 1) != m.end()) ans += m[x[i] - 1];
      m[x[i]]++;
    }
    printf("%lld\n", ans);
  } else {
    long long ans = 0;
    map<long long, int> m;
    for (int i = N; i >= 0; i--) {
      long long cur = 1;
      while (true) {
        if (abs(cur) >= 1e15) break;
        if (m.find(x[i] + cur) != m.end()) ans += m[x[i] + cur];
        cur *= k;
      }
      m[x[i]]++;
    }
    printf("%lld\n", ans);
  }
}
signed main() {
  int t = 1;
  while (t--) {
    solve();
  }
  return 0;
}
