#include <bits/stdc++.h>
using namespace std;
const int N = 5e5;
const int md = 1e9 + 7;
const int MAX = 1e6;
const double ep = 1.19209e-07;
long long int n, k;
long long int ans;
vector<long long int> v;
map<long long int, long long int> fr;
long long int mx;
int main() {
  scanf("%lld%lld", &n, &k);
  v.resize(n);
  for (int i = 0; i < n; i++)
    scanf("%lld", &v[i]), v[i] += i ? v[i - 1] : 0, mx = max(mx, v[i]);
  if (k == 1 || k == -1) {
    for (int i = 0; i < n; i++) {
      ans += fr[v[i] - 1] + (v[i] == 1);
      if (k == -1) {
        ans += v[i] == -1;
        if (!v[i])
          ans += fr[1];
        else if (v[i] > 0)
          ans += fr[v[i] + 1];
        else
          ans += fr[-(abs(v[i]) - 1)];
      }
      fr[v[i]]++;
    }
  } else {
    for (int i = 0; i < n; i++) {
      long long int have = 1;
      while (have <= 1e15) {
        ans += fr[v[i] - have] + (v[i] == have);
        have *= 1LL * k;
      }
      fr[v[i]]++;
    }
  }
  printf("%lld", ans);
  return 0;
}
