#include <bits/stdc++.h>
using namespace std;
const int MAXN = (int)5e5 + 228;
const char nxtl = '\n';
const int mod = (int)1e9 + 7;
const double eps = (double)1e-7;
template <typename T>
inline bool updmin(T &a, const T &b) {
  return a > b ? a = b, 1 : 0;
}
template <typename T>
inline bool updmax(T &a, const T &b) {
  return a < b ? a = b, 1 : 0;
}
int k, n, a[MAXN];
vector<long long> v;
long long K = 1, cnt;
map<long long, long long> M;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> k;
  for (int i = 1; i <= n; ++i) cin >> a[i];
  while (K <= (long long)1e15 && K >= -(long long)1e15) {
    v.push_back(K);
    K = K * 1ll * k;
    if (K == 1) break;
  }
  long long sum = 0ll;
  M[sum] = 1ll;
  for (int i = 1; i <= n; ++i) {
    sum += a[i];
    for (auto &to : v) {
      cnt += M[sum - to];
    }
    M[sum]++;
  }
  cout << cnt << nxtl;
  return 0;
}
