#include <bits/stdc++.h>
using namespace std;
const double EPS = 1e-9;
const long long INF = 1e17;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(nullptr);
  cout.tie(nullptr);
  int n, k;
  cin >> n >> k;
  vector<long long> nums(1, 1);
  if (k == -1) {
    nums.push_back(-1);
  } else if (k != 1) {
    while (nums.back() <= (long long)1e14 && nums.back() >= -1e14) {
      nums.push_back(nums.back() * k);
    }
  }
  vector<long long> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    if (i) a[i] += a[i - 1];
  }
  map<long long, int> cnt;
  cnt[0] = 1;
  long long ans = 0;
  for (int i = 0; i < n; i++) {
    for (auto num : nums) {
      if (cnt.count(num - a[i])) ans += cnt[num - a[i]];
    }
    cnt[-a[i]]++;
  }
  cout << ans << "\n";
  return 0;
}
