#include <bits/stdc++.h>
using namespace std;
long long power(long long a, int b) {
  long long res = 1;
  while (b) {
    if (b & 1) res *= a;
    a *= a;
    b >>= 1;
  }
  return res;
}
map<long long, int> mp;
long long sum[100001];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n, k;
  cin >> n >> k;
  for (int i = 0; i < n; i++) {
    int a;
    cin >> a;
    sum[i + 1] = sum[i] + a;
  }
  mp[0] = 1;
  long long cnt = 0;
  long long m = 0;
  for (int i = 1; i <= n; i++) {
    long long temp = power(k, 0);
    int j = 0;
    while (abs(temp) <= m + abs(sum[i])) {
      cnt += mp[sum[i] - temp];
      temp = power(k, ++j);
      if (k == 1 && j == 1) break;
      if (k == -1 && j == 2) break;
    }
    mp[sum[i]]++;
    m = max(m, abs(sum[i]));
  }
  cout << cnt << "\n";
  return 0;
}
