#include <bits/stdc++.h>
using namespace std;
int32_t main() {
  ios::sync_with_stdio(false);
  cin.tie(0), cout.tie(0);
  long long n, k;
  cin >> n >> k;
  long long a[n];
  for (long long i = 0; i < n; i++) {
    cin >> a[i];
  }
  for (long long i = 1; i < n; i++) {
    a[i] += a[i - 1];
  }
  vector<long long> v;
  v.push_back(1);
  long long x = k;
  while (abs(x) <= 1e14) {
    if (x == 1) break;
    v.push_back(x);
    x *= k;
    if (x == 1 || x == -1) break;
  }
  long long ans = 0;
  map<long long, long long> mp;
  for (long long i = 0; i < v.size(); i++) {
    long long temp = v[i];
    mp.clear();
    for (long long j = 0; j < n; j++) {
      if (a[j] == temp) ans++;
      if (mp.find(a[j] - temp) != mp.end()) ans += mp[a[j] - temp];
      mp[a[j]]++;
    }
  }
  cout << ans;
  return 0;
}
