#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
long long powmod(long long a, long long b) {
  long long res = 1;
  a %= mod;
  assert(b >= 0);
  for (; b; b >>= 1) {
    if (b & 1) res = res * a % mod;
    a = a * a % mod;
  }
  return res;
}
const int N = 101000;
int n, k, a[N];
long long s[N], ret;
set<long long> hs;
map<long long, int> cnt;
int main() {
  scanf("%d%d", &n, &k);
  for (int i = 1; i < n + 1; i++) {
    scanf("%d", a + i);
    s[i] = s[i - 1] + a[i];
  }
  hs.insert(1);
  if (k == -1)
    hs.insert(-1);
  else if (k != 1) {
    long long x = 1;
    while (x * k <= (1ll << 60) && x * k >= -(1ll << 60)) {
      x *= k;
      hs.insert(x);
    }
  }
  cnt[0] = 1;
  for (int i = 1; i < n + 1; i++) {
    for (auto p : hs)
      if (cnt.count(s[i] - p)) ret += cnt[s[i] - p];
    cnt[s[i]]++;
  }
  printf("%lld\n", ret);
}
