#include <bits/stdc++.h>
using namespace std;
vector<long long int> kp;
map<long long int, long long int> m;
long long int sum[2000000];
long long int M = 1e14;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long int n, k;
  cin >> n >> k;
  long long int aa = 1;
  int kk = 1;
  long long int lim = 60;
  long long int a[n + 1];
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    if (i == 1) {
      sum[i] = a[i];
    }
    sum[i] = sum[i - 1] + a[i];
  }
  if (k == 1) {
    kp.push_back(1);
  } else if (k == -1) {
    kp.push_back(-1);
    kp.push_back(1);
  } else {
    while (aa <= M and aa >= -M) {
      kp.push_back(aa);
      aa = aa * k;
      kk++;
    }
  }
  long long int cnt = 0;
  m[0] = 1;
  for (int i = 1; i <= n; i++) {
    for (int j = 0; j < kp.size(); j++) {
      long long int key1 = sum[i] - kp[j];
      cnt += m[key1];
    }
    m[sum[i]]++;
  }
  cout << cnt << endl;
  return 0;
}
