#include <bits/stdc++.h>
using namespace std;
const long long inf = 1e14;
vector<long long> sum;
map<long long, int> mp;
int main() {
  ios::sync_with_stdio(false);
  int n, k;
  long long x, res = 0, p;
  cin >> n >> k;
  sum.assign(n + 1, 0);
  for (int i = 1; i <= n; ++i) {
    cin >> x;
    sum[i] = sum[i - 1] + x;
  }
  mp[0] = 1;
  if (abs(k) == 1) {
    for (int i = 1; i <= n; ++i) {
      x = sum[i] - 1;
      res += mp[x];
      if (k == -1) {
        x = sum[i] + 1;
        res += mp[x];
      }
      ++mp[sum[i]];
    }
    cout << res << '\n';
  } else {
    for (int i = 1; i <= n; ++i) {
      for (p = 1; abs(p) <= inf; p *= k) {
        x = sum[i] - p;
        res += mp[x];
      }
      ++mp[sum[i]];
    }
    cout << res << '\n';
  }
  return 0;
}
