#include <bits/stdc++.h>
using namespace std;
long long int n, k;
long long int a[1000001];
long long int prefix[1000001];
map<long long int, long long int> save;
vector<long long int> power;
int main() {
  cin >> n >> k;
  for (long long int i = 1; i <= n; i++) {
    cin >> a[i];
  }
  if (k == 1) {
    power.push_back(1);
  } else if (k == -1) {
    power.push_back(1);
    power.push_back(-1);
  } else {
    long long int temp = 1;
    while (temp <= 1e16) {
      power.push_back(temp);
      temp = temp * k;
    }
  }
  for (long long int i = 1; i <= n; i++) {
    prefix[i] = prefix[i - 1] + a[i];
  }
  save[0] = 1;
  long long int ans = 0;
  for (long long int i = 1; i <= n; i++) {
    long long int val = prefix[i];
    save[val]++;
    for (long long int j = 0; j < power.size(); j++) {
      long long int req = val - power[j];
      ans = ans + save[req];
    }
  }
  cout << ans;
}
