#include <bits/stdc++.h>
using namespace std;
const long long linf = 1e18, mod = 1e9 + 7;
const int N = 3e5, inf = 1e9;
long long n, k, a[N], sum[N], pref[N], ans;
map<long long, long long> m;
vector<long long> v;
int main() {
  cin >> n >> k;
  for (int i = 1; i <= n; i++) {
    scanf("%I64d", &a[i]);
    sum[i] = sum[i - 1] + a[i];
  }
  for (int i = n; i > 0; i--) {
    pref[i] = pref[i + 1] + a[i];
    m[pref[i]]++;
  }
  m[0]++;
  if (k == -1) {
    v.push_back(1);
    v.push_back(-1);
  } else if (k == 1)
    v.push_back(1);
  else {
    v.push_back(1);
    for (int i = 1; v[v.size() - 1] * k <= 1e15 + 1111; i++)
      v.push_back(v[v.size() - 1] * k);
  }
  for (int i = 0; i <= n; i++) {
    m[pref[i + 1]]--;
    for (int j = 0; j < v.size(); j++)
      if (m[sum[n] - (v[j] + sum[i])]) {
        ans += m[sum[n] - (v[j] + sum[i])];
      }
  }
  cout << ans;
  return 0;
}
