#include <bits/stdc++.h>
using namespace std;
vector<long long> g;
long long n, k;
const long long MX = (1e16);
void init() {
  long long value = 1;
  for (long long i = 0, to = 60; i < to; i++) {
    if (abs(value) <= MX)
      g.push_back(value);
    else
      break;
    value *= k;
  }
}
map<long long, int> M;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);
  cin >> n >> k;
  M[0]++;
  if (k == 1) {
    g.push_back(1LL);
  } else if (k == -1) {
    g.push_back(-1LL);
    g.push_back(1LL);
  } else {
    init();
  }
  long long ans = 0;
  long long num;
  long long acum = 0;
  for (long long i = 0, to = n; i < to; i++) {
    cin >> num;
    acum += num;
    for (long long j = 0, to = (int)g.size(); j < to; j++) {
      long long need = acum - g[j];
      if (M.count(need)) ans += M[need];
    }
    M[acum]++;
  }
  cout << ans << endl;
  return 0;
}
