#include <bits/stdc++.h>
using namespace std;
long long n, k;
long long a[100013];
long long pr[100013];
long long su[100013];
long long sum = 0;
int main() {
  cin >> n >> k;
  for (long long i = 0; i < n; ++i) {
    cin >> a[i];
    sum += a[i];
  }
  for (long long i = 1; i <= n; ++i) {
    pr[i] = pr[i - 1] + a[i - 1];
  }
  for (long long i = n - 1; i >= 0; --i) {
    su[i] = su[i + 1] + a[i];
  }
  long long out = 0;
  if (k == 1) {
    int kof = 1;
    map<long long, long long> mp;
    for (int i = 0; i <= n; ++i) {
      ++mp[su[i]];
    }
    for (int i = 0; i <= n; ++i) {
      out += mp[sum - kof - pr[i]];
      --mp[su[i]];
    }
    cout << out;
    return 0;
  }
  if (k == -1) {
    for (long long kof = 1, i = 0; i <= 1; kof *= k, ++i) {
      map<long long, long long> mp;
      for (int i = 0; i <= n; ++i) {
        ++mp[su[i]];
      }
      for (int i = 0; i <= n; ++i) {
        out += mp[sum - kof - pr[i]];
        --mp[su[i]];
      }
    }
    cout << out;
    return 0;
  }
  for (long long kof = 1; kof <= 10000000000000000; kof *= k) {
    map<long long, long long> mp;
    for (int i = 0; i <= n; ++i) {
      ++mp[su[i]];
    }
    for (int i = 0; i <= n; ++i) {
      out += mp[sum - kof - pr[i]];
      --mp[su[i]];
    }
  }
  cout << out;
  return 0;
}
