#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e5 + 100;
const long long MAXVALUE = 1e17;
map<long long, long long> mp;
long long a[MAXN];
long long sum[MAXN];
long long n, k, res, value, kMi;
int main() {
  scanf("%I64d%I64d", &n, &k);
  res = 0;
  sum[0] = 0;
  for (int i = 1; i < n + 1; i++) {
    scanf("%I64d", &a[i]);
    sum[i] = sum[i - 1] + a[i];
  }
  for (int i = n + 1 - 1; i >= 0; i--) {
    value = sum[i];
    if (k == 1) {
      res += mp[value + k];
    } else if (k == -1) {
      res += mp[value + 1];
      res += mp[value - 1];
    } else {
      kMi = 1;
      while (abs(kMi) < MAXVALUE) {
        res += mp[value + kMi];
        kMi *= k;
      }
    }
    mp[value]++;
  }
  printf("%I64d\n", res);
  return 0;
}
