#include <bits/stdc++.h>
using namespace std;
int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); }
int lcm(int a, int b) { return a * (b / gcd(a, b)); }
const int maxSize = 100000 + 5;
int main() {
  int n, k;
  cin >> n >> k;
  vector<long long int> arr(n);
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
  }
  vector<long long int> pwr;
  long long int limit = 1e14;
  long long int ans = 1;
  pwr.push_back(1);
  if (abs(k) > 1) {
    while (ans * k <= limit) {
      ans *= k;
      pwr.push_back(ans);
    }
  } else if (k == -1) {
    pwr.push_back(-1);
  }
  map<long long int, long long int> make_pair;
  long long int sum = 0;
  ans = 0;
  for (int i = 0; i < n; i++) {
    make_pair[sum]++;
    sum += arr[i];
    for (auto pw : pwr) {
      if (make_pair.count(sum - pw) > 0) {
        ans += make_pair[sum - pw];
      }
    }
  }
  cout << ans;
}
