#include <bits/stdc++.h>
using namespace std;
map<long long, long long> mp;
int main() {
  std::ios_base::sync_with_stdio(false);
  long long n, k;
  cin >> n >> k;
  long long arr[n + 2];
  long long sum[n + 2];
  sum[0] = 0;
  mp[0] = 1;
  for (int i = 1; i <= n; i++) {
    cin >> arr[i];
    sum[i] = sum[i - 1] + arr[i];
  }
  long long mn = 1e15;
  mn *= -1;
  long long mx = 1e15;
  vector<long long> vec;
  vec.push_back(1);
  long long temp = 1;
  while (true) {
    if (k == 1) break;
    if (k == -1) {
      vec.push_back(-1);
      break;
    }
    temp *= k;
    if (temp > mx || temp < mn) break;
    vec.push_back(temp);
  }
  long long ans = 0;
  for (int i = 1; i <= n; i++) {
    mp[sum[i]]++;
    for (int j = 0; j < vec.size(); j++) {
      ans += mp[(sum[i] - vec[j])];
    }
  }
  cout << ans;
  return 0;
}
