#include <bits/stdc++.h>
using namespace std;
const int INF = 1 << 30;
const int N = 1e5 + 10;
long long sum[N];
int main() {
  int n;
  long long k;
  scanf("%d%lld", &n, &k);
  sum[0] = 0;
  for (int i = 1; i <= n; ++i) {
    int x;
    scanf("%d", &x);
    sum[i] = sum[i - 1] + x;
  }
  set<long long> A = {1};
  A.insert(k);
  if (abs(k) > 1) {
    long long prod = k;
    while (true) {
      A.insert(prod);
      prod *= k;
      if (abs(prod) > 1e14) break;
    }
  }
  long long ret = 0;
  for (auto& it : A) {
    map<long long, int> B;
    for (int i = 0; i <= n; ++i) {
      ret += B[sum[i] - it];
      B[sum[i]]++;
    }
  }
  printf("%lld\n", ret);
  return 0;
}
