#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 9;
const long long inf = 1e14;
long long n, k;
int main() {
  long long a, b, c, d, e, f, g, h;
  ios::sync_with_stdio(0);
  cin >> n >> k;
  vector<long long> vec;
  if (abs(k) == 1) {
    vec.push_back(1);
    if (k < 0) vec.push_back(-1);
  } else {
    vec.push_back(1);
    a = k;
    while (abs(a) <= inf) {
      vec.push_back(a);
      a *= k;
    }
  }
  g = 0;
  long long ans = 0;
  map<long long, long long> ma;
  while (n--) {
    cin >> e;
    g += e;
    for (int i = 0; i < vec.size(); i++) {
      if (vec[i] == g) {
        ans++;
        break;
      }
    }
    for (int i = 0; i < vec.size(); i++) {
      e = g - vec[i];
      if (ma.find(e) != ma.end()) {
        ans += ma[e];
      }
    }
    ma[g]++;
  }
  cout << ans << endl;
  return 0;
}
