#include <bits/stdc++.h>
using namespace std;
long long a[100005];
vector<long long> vec;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int i, j, t;
  int n, k;
  long long maxx = -1e18;
  long long minn = 1e18;
  long long sum = 0;
  cin >> n >> k;
  for (i = 0; i < n; i++) {
    cin >> a[i];
    if (i > 0) a[i] += a[i - 1];
  }
  long long ans = 0;
  long long x = 1;
  set<long long> sett;
  while (1) {
    vec.push_back(x);
    sett.insert(x);
    if (1.0 * abs(x) > 1e15 / abs(k)) break;
    x *= k;
    if (sett.find(x) != sett.end()) break;
  }
  unordered_map<long long, int> mapp;
  mapp[0] = 1;
  for (i = 0; i < n; i++) {
    for (long long p : vec) {
      if (mapp.find(a[i] - p) != mapp.end()) {
        ans += mapp[a[i] - p];
      }
    }
    mapp[a[i]]++;
  }
  cout << ans << endl;
  return 0;
}
