#include <bits/stdc++.h>
using namespace std;
const long long inf = 1000000000000000000LL;
const int MAXN = 100005;
int n, k;
long long a[MAXN];
map<long long, long long> cnt;
int main(void) {
  scanf("%d%d", &n, &k);
  for (int i = (1); i < (n + 1); ++i) scanf("%lld", a + i);
  for (int i = (0); i < (n); ++i) a[i + 1] += a[i];
  vector<long long> powers;
  if (k == 1) {
    powers.push_back(1);
  } else if (k == -1) {
    powers.push_back(1);
    powers.push_back(-1);
  } else {
    long long x = 1;
    while (abs(x) < 1e17) {
      powers.push_back(x);
      x *= k;
    }
  }
  long long sol = 0;
  for (int i = (0); i < (n + 1); ++i) {
    for (long long p : powers) {
      sol += cnt[a[i] - p];
    }
    ++cnt[a[i]];
  }
  printf("%lld\n", sol);
  return 0;
}
