#include <bits/stdc++.h>
using namespace std;
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
void solve() {
  long long n, k;
  cin >> n >> k;
  vector<long long> a(n), p(n + 1);
  for (long long i = (0); i < (n); i++) cin >> a[i], p[i + 1] = p[i] + a[i];
  long long ans = 0;
  map<long long, long long> m;
  for (long long i = (n + 1 - 1); i >= (0); i--) {
    if (k == 1) {
      ans += m[p[i] + 1];
    } else if (k == -1) {
      ans += m[p[i] + 1];
      ans += m[p[i] - 1];
    } else {
      long long kk = 1;
      while (1) {
        if (kk > 100000000000000) break;
        ans += m[p[i] + kk];
        kk *= k;
      }
    }
    m[p[i]]++;
  }
  cout << ans << "\n";
}
int32_t main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  solve();
  return 0;
}
