#include <bits/stdc++.h>
using namespace std;
map<long long, int> cnt;
int n;
long long k;
int mas[100005];
void pre() {}
void load() {
  cin >> n >> k;
  for (int i = 0; i < n; i++) cin >> mas[i];
}
int get(long long v) {
  auto it = cnt.find(v);
  if (it == cnt.end()) return 0;
  return it->second;
}
void solve() {
  const long long MX = 1e15;
  long long sum = 0;
  long long ans = 0;
  for (int i = 0; i < n; i++) {
    cnt[-sum]++;
    sum += mas[i];
    long long v = 1;
    set<long long> was;
    for (int j = 0; abs(v) <= MX && j < 64; j++) {
      if (was.count(v)) break;
      was.insert(v);
      ans += get(v - sum);
      v *= k;
    }
  }
  cout << ans << endl;
}
void clear() {}
int main() {
  double st = clock();
  pre();
  load();
  solve();
  clear();
  return 0;
}
