#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
int main() {
  long long n, k;
  scanf("%I64d %I64d", &n, &k);
  long long power[100], num = 0;
  if (k != 1 && k != -1)
    for (long long i = 1; i < 1e16 && i > -1e16; i *= k, num++) power[num] = i;
  else if (k == 1) {
    power[0] = 1;
    num = 1;
  } else if (k == -1) {
    power[0] = 1;
    power[1] = -1;
    num = 2;
  }
  long long a[500005];
  for (int i = 0; i < n; i++) scanf("%I64d", &a[i]);
  map<long long, int> m;
  m[0] = 1;
  long long sum = 0;
  long long ans = 0;
  for (int i = 0; i < n; i++) {
    sum += a[i];
    for (int j = 0; j < num; j++) ans += m[sum - power[j]];
    m[sum]++;
  }
  printf("%I64d\n", ans);
}
