#include <bits/stdc++.h>
using namespace std;
int static_init = []() {
  ios_base::sync_with_stdio(false), cin.tie(0), cout << fixed;
  return 0;
}();
struct custom_hash {
  static uint64_t splitmix64(uint64_t x) {
    x += 0x9e3779b97f4a7c15;
    x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
    x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
    return x ^ (x >> 31);
  }
  size_t operator()(uint64_t x) const {
    static const uint64_t FIXED_RANDOM =
        chrono::steady_clock::now().time_since_epoch().count();
    return splitmix64(x + FIXED_RANDOM);
  }
};
constexpr int N = 1e5;
int32_t n, k, a[N];
unordered_set<int64_t> kp;
unordered_map<int64_t, int32_t, custom_hash> c;
int64_t run(int l, int r) {
  if (l == r) return kp.count(a[l]);
  int m = (l + r) / 2;
  auto ans = run(l, m) + run(m + 1, r);
  c.clear();
  int64_t s = 0;
  for (int i = m; i >= l; i--) c[s += a[i]]++;
  s = 0;
  for (int i = m + 1; i <= r; i++) {
    s += a[i];
    for (auto x : kp) {
      auto it = c.find(x - s);
      if (it != c.end()) ans += it->second;
    }
  }
  return ans;
}
int main() {
  cin >> n >> k;
  for (int i = 0; i < n; i++) cin >> a[i];
  for (int64_t x = 1; x <= 1e14; x *= k) {
    if (!kp.insert(x).second) break;
  }
  c.reserve(n);
  cout << run(0, n - 1) << endl;
  return 0;
}
