#include <bits/stdc++.h>
using namespace std;
const long long oo = 1e14;
long long ab(long long x) { return x > 0 ? x : -x; }
long long a[100005];
long long kn[66];
long long sum[100005];
map<long long, int> mp;
int nxt[100005];
int main() {
  int n, k;
  scanf("%d%d", &n, &k);
  kn[0] = 1;
  int cnt = 0;
  for (int i = 1;; i++) {
    kn[i] = kn[i - 1] * k;
    if (kn[i] == 1) break;
    cnt++;
    if (ab(kn[i]) >= oo) break;
  }
  for (int i = 1; i <= n; i++) {
    scanf("%lld", &a[i]);
    sum[i] = sum[i - 1] + a[i];
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j <= cnt; j++) {
      mp[sum[n] - sum[i] - kn[j]]++;
    }
  }
  long long ans = 0, step = 0;
  for (int i = n; i >= 1; i--) {
    ans += mp[step];
    for (int j = 0; j <= cnt; j++) {
      mp[sum[n] - sum[i - 1] - kn[j]]--;
    }
    step += a[i];
  }
  printf("%lld\n", ans);
  return 0;
}
