#include <bits/stdc++.h>
using namespace std;
long long mx = (long long)1ll * 1e5 * 1e9 * 10;
signed main() {
  int n, k;
  cin >> n >> k;
  map<long long, int> mp;
  long long cur = 1ll;
  int cnt = 0;
  set<long long> all;
  all.insert(1ll);
  while (abs(cur) < mx && cnt < 64) {
    all.insert(cur * 1ll * k);
    cur *= 1ll * k;
    cnt++;
  }
  long long pref = 0, ans = 0;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    pref += 1ll * a[i];
    ans += (all.find(pref) != all.end());
    mp[pref]++;
  }
  pref = 0;
  for (int i = 1; i < n; i++) {
    pref += 1ll * a[i - 1];
    mp[pref]--;
    for (auto j : all) {
      ans += mp[j + pref];
    }
  }
  cout << ans;
  return 0;
}
