#include <bits/stdc++.h>
using namespace std;
long long a[100005], sum[100005];
map<long long, long long> M;
int main() {
  int n;
  long long k;
  cin >> n >> k;
  long long p = 1;
  long long maxx = 10000000000000000LL, minn = -10000000000LL;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    sum[i] = sum[i - 1] + a[i];
    M[sum[i]]++;
  }
  long long ans = 0;
  for (int i = 1; i <= n; i++) {
    long long x = 0, g = 1;
    p = 1;
    while ((abs(p) <= maxx) && g) {
      x = sum[i - 1] + p;
      ans += M[x];
      p = p * k;
      g++;
      if (k == 1) {
        g = 0;
      } else if (k == -1) {
        if (g == 3) {
          g = 0;
        }
      }
    }
    M[sum[i]]--;
  }
  cout << ans;
  return 0;
}
