#include <bits/stdc++.h>
using namespace std;
const int maxn = 100005;
using ll = long long;
ll a[maxn], pref[maxn];
int n;
ll get(ll k) {
  ll ret = 0;
  map<ll, int> mp;
  mp[0] = 1;
  for (int i = 1; i <= n; ++i) {
    ret += mp[pref[i] - k];
    mp[pref[i]]++;
  }
  return ret;
}
int main(int argc, char const *argv[]) {
  ll k;
  scanf("%d %lld", &n, &k);
  int pos = 0, neg = 0;
  for (int i = 1; i <= n; ++i) {
    scanf("%lld", &a[i]);
    if (a[i] >= 1) {
      pos = 1;
    }
    if (a[i] <= -1) {
      neg = 1;
    }
    pref[i] = pref[i - 1] + a[i];
  }
  if (llabs(k) == 1) {
    ll ans = 0;
    if (k == 1) {
      cout << get(1) << endl;
    } else {
      ans += get(1);
      ans += get(-1);
      cout << ans << endl;
    }
  } else {
    ll ans = get(1);
    ll kk = k;
    while (llabs(kk) <= 100000000000000LL) {
      ans += get(kk);
      kk *= k;
    }
    cout << ans << endl;
  }
  return 0;
}
