#include <bits/stdc++.h>
using namespace std;
map<long long, long long> ct;
long long a[100010];
long long power[1000];
long long check_count(long long cumsumj, int powcount) {
  long long ans = 0;
  for (int i = 0; i < powcount; i++) {
    long long temp = cumsumj - power[i];
    ans += ct[temp];
  }
  return ans;
}
long long absd(long long a) {
  if (a < 0) return -a;
  return a;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long n, k;
  cin >> n >> k;
  int powcount = 0;
  for (int i = 0; i < n; i++) cin >> a[i];
  for (int i = 1; i < n; i++) a[i] += a[i - 1];
  if (k == 1) {
    power[0] = 1;
    powcount = 1;
  } else if (k == -1) {
    power[0] = -1;
    power[1] = 1;
    powcount = 2;
  } else {
    for (long long temp = 1; absd(temp) <= 100000000000010; powcount++) {
      power[powcount] = temp;
      temp = temp * k;
    }
  }
  long long ans = 0;
  ct[0] = 1;
  for (int i = 0; i < n; i++) {
    ct[a[i]]++;
    ans += check_count(a[i], powcount);
  }
  cout << ans << endl;
  return 0;
}
