#include <bits/stdc++.h>
using namespace std;
int a[100100];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  int n, k;
  cin >> n >> k;
  for (int i = 0; i < n; i++) cin >> a[i];
  const long long max_pow = 1e9 * 1e5;
  vector<long long> powers = {1};
  if (abs(k) > 1)
    while (abs(powers.back() * k) <= max_pow)
      powers.push_back(powers.back() * k);
  else if (k == -1)
    powers.push_back(-1);
  long long ans = 0;
  long long prefix_sum = 0;
  map<long long, long long> cnt_sums;
  for (int i = 0; i < n; i++) {
    cnt_sums[prefix_sum]++;
    prefix_sum += a[i];
    for (auto pow : powers)
      if (cnt_sums.count(prefix_sum - pow) > 0)
        ans += cnt_sums[prefix_sum - pow];
  }
  cout << ans;
}
