#include <bits/stdc++.h>
using namespace std;
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
  cerr << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << " : " << arg1 << " | ";
  __f(comma + 1, args...);
}
const int mod = 1000000007;
const int inf = 50000000;
const int maxn = 100010;
const long long lim = 1LL << 53;
int n, A[maxn];
long long k, pref[maxn];
map<long long, int> cnt;
int main() {
  scanf("%d %lld", &n, &k);
  cnt[0] = 1;
  long long ans = 0;
  for (int i = 1; i <= n; i++) {
    scanf("%d", &A[i]);
    pref[i] = pref[i - 1] + A[i];
    if (k == 1) {
      ans += cnt[pref[i] - 1];
    } else if (k == -1) {
      ans += cnt[pref[i] - 1];
      ans += cnt[pref[i] + 1];
    } else {
      long long tmp = 1;
      while (tmp < lim) {
        ans += cnt[pref[i] - tmp];
        tmp *= k;
      }
    }
    cnt[pref[i]] += 1;
  }
  printf("%lld\n", ans);
  return 0;
}
