#include <bits/stdc++.h>
using namespace ::std;
const int maxn = 1e5 + 5;
map<long long, int> mp;
long long sum[maxn], ans;
int n, k;
void solve() {
  long long maxx = 0, minn = 0;
  scanf("%d%d", &n, &k);
  mp[0] = 1;
  for (int i = 1; i <= n; i++) {
    long long tmp;
    scanf("%I64d", &tmp);
    sum[i] = sum[i - 1] + tmp;
    mp[sum[i]]++;
    maxx = max(maxx, sum[i]);
    minn = min(minn, sum[i]);
    for (long long j = 1; - 1e15 <= j && j <= 1e15; j *= k) {
      if (mp.find(sum[i] - j) != mp.end()) {
        ans += mp[sum[i] - j];
      }
      if (k == 1) break;
      if (j == -1 && k == -1) break;
    }
  }
  printf("%I64d\n", ans);
}
int main() {
  solve();
  return 0;
}
