#include <bits/stdc++.h>
using namespace std;
const long long N = 1e5 + 5, INF = 1e15;
long long n, k, a[N], dp[N], x, ans;
vector<long long> v;
inline long long sum(long long k) {
  long long res = 0;
  map<long long, long long> mp;
  for (long long i = 1; i <= n; i++) {
    res += mp[dp[i] - k];
    if (dp[i] == k) res++;
    mp[dp[i]]++;
  }
  return res;
}
int main() {
  cin >> n >> k;
  for (long long i = 1; i <= n; i++) {
    cin >> a[i];
    dp[i] = dp[i - 1] + a[i];
  }
  v.push_back(1);
  if (k == -1)
    v.push_back(-1);
  else if (k != 1) {
    x = k;
    while (k < INF) {
      v.push_back(k);
      k *= x;
    }
  }
  for (long long i = 0; i < v.size(); i++) ans += sum(v[i]);
  cout << ans;
}
