#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
array<int, N> a;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n, k;
  cin >> n >> k;
  for (int i = 0; i < n; i++) cin >> a[i];
  long long ans = 0;
  long long power = 1;
  while (abs(power) < 1e15) {
    map<long long, int> m;
    m[0] = 1;
    long long sum = 0ll;
    for (int i = 0; i < n; i++) {
      sum += a[i];
      ans += m[sum - power];
      m[sum]++;
    }
    power *= k;
    if (power == 1) break;
  }
  cout << ans << endl;
  return 0;
}
